引导日期选择器不工作

问题描述:

我想获得引导日期选择器的工作,但它甚至不露面。

http://www.eyecon.ro/bootstrap-datepicker/

I am trying to get bootstrap datepicker to work but it does not even show up.
http://www.eyecon.ro/bootstrap-datepicker/

<link href="~/Css/datepicker.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.8.1.js" type="text/javascript"></script>
<script src="~/Scripts/bootstrap-datepicker.js" type="text/javascript"></script>
<script type="text/javascript">
    $("#datepicker").datepicker();
</script>

<input id="datepicker" value="10/22/2011" />

我使用的引导2.1.1

I am using bootstrap 2.1.1

它看起来像你想初始化一个datepicker时,有一个在DOM没有 #datepicker 元素尚未(相应的输入如下&LT;脚本&GT; 元素,而不是相反)。

It looks like you're trying to initialize a datepicker when there's no #datepicker element in DOM yet (the corresponding input follows <script> element, not vice versa).

由于 $('#日期选择器')仍然会返回一个jQuery包裹的对象(而不是!) ,没有错误将被抛出。

As $('#datepicker') will still return a jQuery-wrapped object (not null!), no error will be thrown.

要解决这个问题,要么使DOM时加载此调用:

To solve this, either make this call when DOM is loaded:

$(function() {
  $('#datepicker').datepicker();
});

或移动这个脚本到&LT的尽头;身体GT; 元素。

or move this script into very end of <body> element.

我就选择了第一个选项;移动所有的DOM准备行动纳入同一 $(函数(){...}); 包装以及

I'd choose the first option; moving all the DOM-ready actions into the same $(function() { ... }); wrapper as well.