Bootstrap 日期选择器不工作 [英] Bootstrap Datepicker Not Working
问题描述
我试图让引导日期选择器工作,但它甚至没有出现.
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
推荐答案
当 DOM 中还没有 #datepicker
元素(相应的 input
跟在 元素之后,反之亦然).
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).
由于 $('#datepicker')
仍然会返回一个 jQuery 包装的对象(不是 null
!),所以不会抛出错误.
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();
});
或将此脚本移动到 元素的最后.
or move this script into very end of <body>
element.
我会选择第一个选项;将所有 DOM 就绪操作也移动到相同的 $(function() { ... });
包装器中.
I'd choose the first option; moving all the DOM-ready actions into the same $(function() { ... });
wrapper as well.
这篇关于Bootstrap 日期选择器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!