twitter-bootstrap Bootstrap 日期选择器不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13058725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap Datepicker Not Working
提问by Bob
I am trying to get bootstrap datepicker to work but it does not even show up.
http://www.eyecon.ro/bootstrap-datepicker/
我试图让引导日期选择器工作,但它甚至没有出现。
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" />
I am using bootstrap 2.1.1
我正在使用引导程序 2.1.1
回答by raina77ow
It looks like you're trying to initialize a datepicker when there's no #datepickerelement in DOM yet (the corresponding inputfollows <script>element, not vice versa).
当#datepickerDOM 中还没有元素(相应的input后续<script>元素,反之亦然)时,您似乎正在尝试初始化日期选择器。
As $('#datepicker')will still return a jQuery-wrapped object (not null!), no error will be thrown.
由于$('#datepicker')仍会返回一个 jQuery 包装的对象(不是null!),因此不会抛出任何错误。
To solve this, either make this call when DOM is loaded:
要解决此问题,请在加载 DOM 时进行此调用:
$(function() {
$('#datepicker').datepicker();
});
or move this script into very end of <body>element.
或将此脚本移至<body>元素的最末端。
I'd choose the first option; moving all the DOM-ready actions into the same $(function() { ... });wrapper as well.
我会选择第一个选项;将所有 DOM 就绪操作也移动到同一个$(function() { ... });包装器中。

