引导日期选择器不工作 [英] Bootstrap Datepicker Not Working

查看:144
本文介绍了引导日期选择器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于引导日期选择器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆