jQuery 对象没有日期选择器方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11761105/
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
Object has no method datepicker
提问by jaimerump
I'm getting the error Uncaught TypeError: Object [object Object] has no method 'datepicker'
in my javascript here:
我Uncaught TypeError: Object [object Object] has no method 'datepicker'
在这里的 javascript 中收到错误消息:
<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>
Here's the birthday item that I'm trying to add it to:
这是我尝试将其添加到的生日项目:
<!--// BIRTHDAY //-->
<li class="field">
<label for="birthday">Birthday</label>
<div class="field"><input type="text" id="birthday" name="birthday" value="" class="" /></div>
</li>
As you can see, I'm including the source for jquery ui just above where I'm trying to use the datepicker. I got the URL from http://jqueryui.com/docs/Downloading_jQuery_UIso I'm pretty sure it's a valid URL. I also tried uploading the file and linking to the local copy and I still got the same error. What else can I try?
如您所见,我在尝试使用日期选择器的上方包含了 jquery ui 的源代码。我从http://jqueryui.com/docs/Downloading_jQuery_UI得到了 URL,所以我很确定它是一个有效的 URL。我还尝试上传文件并链接到本地副本,但仍然出现相同的错误。我还能尝试什么?
EDIT:
编辑:
I do have the jquery library loaded using this: <script type="text/javascript" src="/includes/js/jquery-1.7.2.min.js"></script>
and verified with this bit of script:
我确实使用此加载了 jquery 库:<script type="text/javascript" src="/includes/js/jquery-1.7.2.min.js"></script>
并使用以下脚本进行了验证:
if (jQuery) {
alert("jQuery library is loaded!");
}
回答by Phillip Schmidt
From our discussion, we found that the $ variable (an alias to jQuery
) was not behaving normally. Usually, this is because another JS plugin has changed $
to represent something else. To get around this, you can wrap your jQuery code like this:
从我们的讨论中,我们发现 $ 变量( 的别名jQuery
)表现不正常。通常,这是因为另一个 JS 插件已更改$
为代表其他内容。为了解决这个问题,你可以像这样包装你的 jQuery 代码:
jQuery(function($){
//all jQuery code which uses $ needs to be inside here
});
This will change the meaning of $ within the scope of the function.
这将在函数范围内改变 $ 的含义。
回答by Saeid Zebardast
You may be having a jQuery conflict. Give it a try in noConflict mode like so:
您可能遇到了 jQuery 冲突。在 noConflict 模式下尝试一下,如下所示:
<script type="text/javascript">
(function($) {
$(document).ready(function(){
$("#datepicker").datepicker();
});
})(jQuery);
</script>
回答by Muhammad Hasan
$ will work like
$ 会像
$(function($) {
$( "#dateTasted" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd"
});
});
回答by kovarov
<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>