Object没有方法datepicker

时间:2012-08-01 14:08:47

标签: jquery jquery-ui datepicker

我在这里的javascript中收到错误Uncaught TypeError: Object [object Object] has no method 'datepicker'

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<script type='text/javascript'>
$(function() {
    $("#birthday").datepicker({changeMonth: true});
});
</script>

这是我正在尝试将其添加到的生日项目:

<!--// BIRTHDAY //-->
<li class="field">
    <label for="birthday">Birthday</label>
    <div class="field"><input type="text" id="birthday" name="birthday" value="" class="" /></div>
</li>

正如你所看到的,我正在将jquery ui的源代码包含在我正在尝试使用datepicker的地方。我从http://jqueryui.com/docs/Downloading_jQuery_UI获得了网址,所以我很确定它是一个有效的网址。我也尝试上传文件并链接到本地​​副本,我仍然遇到同样的错误。我还能尝试什么?

编辑:

我确实使用这个加载了jquery库:<script type="text/javascript" src="/includes/js/jquery-1.7.2.min.js"></script>并使用这段脚本进行了验证:

if (jQuery) {
    alert("jQuery library is loaded!");
}

4 个答案:

答案 0 :(得分:23)

从我们的讨论中,我们发现$ variable(jQuery的别名)表现不正常。通常,这是因为另一个JS插件已更改$以表示其他内容。为了解决这个问题,你可以像这样包装你的jQuery代码:

jQuery(function($){
    //all jQuery code which uses $ needs to be inside here
});

这将改变函数范围内$的含义。

答案 1 :(得分:3)

您可能遇到了jQuery冲突。试试noConflict模式,如下所示:

<script type="text/javascript">
    (function($) {
        $(document).ready(function(){
            $("#datepicker").datepicker();
        });
    })(jQuery);
</script>

答案 2 :(得分:1)

$将像

一样工作
$(function($) {
    $( "#dateTasted" ).datepicker({
      changeMonth: true,
      changeYear: true,
      dateFormat: "yy-mm-dd"    
    });
});

答案 3 :(得分:0)

<script type="text/javascript">
 (function($){
         var pickerOpts = {
           // minDate: new Date(),
            //maxDate: "+3m,",
            showButtonPanel: true,
            showOn: "button",
            buttonImage: "images/cal.png",
            };
    $("#birthday").datepicker(pickerOpts);
      })(jQuery);
</script>  

link source solution