jQuery Bootstrap 日期选择器根本不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15536765/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:16:20  来源:igfitidea点击:

Bootstrap datepicker not working at all

jquerytwitter-bootstrapdatepicker

提问by Soulipsyz

I've been trying to get bootstrap datepicker from here: https://github.com/eternicode/bootstrap-datepickerto work but the calender won't show up at all. Not sure what I'm missing? I've linked everything correctly. Any help would be great, thanks!

我一直在尝试从这里获取引导日期选择器:https: //github.com/eternicode/bootstrap-datepicker工作,但日历根本不会出现。不确定我缺少什么?我已经正确链接了所有内容。任何帮助都会很棒,谢谢!

<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/datepicker.css" rel="stylesheet">

<input type="text" value="02/16/12" data-date-format="mm/dd/yy" class="datepicker" >

<script src="js/bootstrap.js"></script>
<script src="js/jquery-1.7.1.js"></script>  
<script src="js/bootstrap-datepicker.js"></script>

<script type="text/javascript">
$('.datepicker').datepicker();
</script>   

采纳答案by powtac

$(document).ready(function() {
    $('.datepicker').datepicker();
})

It works on hereI used jQuery 1.7.2, Bootstrap 2.0.2 and the latest datepicker JS. CSS is missing in my test, but the datepicker occurs on click! :-)

它在这里工作,我使用了 jQuery 1.7.2、Bootstrap 2.0.2 和最新的datepicker JS。我的测试中缺少 CSS,但单击时会出现日期选择器!:-)

回答by Todd

You need to load jquery before you load bootstrap.js, in addition to adding the $(document).ready().

除了添加 $(document).ready() 之外,您还需要在加载 bootstrap.js 之前加载 jquery。

<script src="js/jquery-1.7.1.js"></script>  
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap-datepicker.js"></script>

Hope that helps.

希望有帮助。