javascript 类型错误:$(...).datepicker 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19510883/
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
TypeError: $(...).datepicker is not a function
提问by Asad Nadeem
I am using Yii Framework to develop an application. I am using
我正在使用 Yii 框架开发应用程序。我在用
$(document).ready(function(){
$('.date-picker').datepicker();
});
everywhere it is running, but when I am placing it in index.php view file, then it is giving me the following error in firefox console:
它在任何地方运行,但是当我将它放在 index.php 视图文件中时,它在 Firefox 控制台中给了我以下错误:
TypeError: $(...).datepicker is not a function
$('.date-picker').datepicker();
类型错误:$(...).datepicker 不是函数
$('.date-picker').datepicker();
I have search the above error everywhere but no solutions are applicable in my criteria from stackoverflow, and other blogs for this query.
我到处搜索上述错误,但没有解决方案适用于我来自 stackoverflow 和此查询的其他博客的标准。
Thanks
谢谢
采纳答案by Dency G B
Try to include jquery library files in your view page. I had the same problem two weeks ago,but when i called it separetely my problem got solved.
尝试在您的视图页面中包含 jquery 库文件。两周前我遇到了同样的问题,但是当我单独调用它时,我的问题得到了解决。
<?php
Yii::app()->clientScript->registerCoreScript('jquery');
Yii::app()->clientScript->registerCoreScript('jquery.ui');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl .'/js/jquery.ui.datepicker.js'); ?>
回答by Saran
The source of your error is most probably the noConflict()setting for jQuery. Here's the reasoning from Wordpress Function Reference:
错误的根源很可能是jQuery的noConflict()设置。这是Wordpress 函数参考的推理:
The jQuery library included with WordPress is set to the noConflict()mode (see wp-includes/js/jquery/jquery.js). This is to prevent compatibility problems with other JavaScript libraries that WordPress can link.
In the noConflict()mode, the global $ shortcut for jQuery is not available.
WordPress 附带的 jQuery 库设置为noConflict()模式(请参阅wp-includes/js/jquery/jquery.js)。这是为了防止与 WordPress 可以链接的其他 JavaScript 库出现兼容性问题。
在noConflict()模式下,jQuery 的全局 $ 快捷方式不可用。
You just have to substitute $
for jQuery
and your code will work.
你只需要替换$
为jQuery
您的代码将工作。
Try this:
试试这个:
jQuery(document).ready(function() {
jQuery('.date-picker').datepicker();
});
Or, you could continue using $
if you pass it in the function, like this:
或者,$
如果在函数中传递它,则可以继续使用,如下所示:
jQuery(document).ready(function($) {
$('.date-picker').datepicker();
});
回答by Praveen
Yii Framework
don't provide default datepicker. You must either use any of the extensions for datepicker.
Yii Framework
不要提供默认的 datepicker。您必须使用 datepicker 的任何扩展。
Check datepicker extension for yii framework. Also check jQuery-ui datepicker in Yii framework