为什么jqueryUI datepicker会抛出错误?

时间:2021-05-27 15:39:53

I am trying out jqueryUI, but firebug catches the following error on this script:

我正在尝试jqueryUI,但firebug在此脚本上捕获以下错误:

$(function(){$("#date").datepicker()});

The firebug error reads:

萤火虫错误如下:

$("#date").datepicker is not a function

On my html, the "date" id looks like this:

在我的HTML上,“日期”ID如下所示:

<input type="text" name="date" id="date" >

NB: I have used the correct JqueryUI css/js scripts on the section

注意:我在该部分使用了正确的JqueryUI css / js脚本

Nothing is executing...

什么都没有执行......

6 个解决方案

#1


jQuery documentation says you can call the datepicker by this command:

jQuery文档说你可以通过这个命令调用datepicker:

$("#datepicker").datepicker();

If you click the 'view source' button on the documentation page you can see that they've wrapped it into the ready function:

如果单击文档页面上的“查看源”按钮,您可以看到它们已将其包装到ready函数中:

$(document).ready(function(){
    $("#datepicker").datepicker();
  });

EDIT: It should work with INPUT (thanks for pointing this out Steerpike). This is the test I've written and it works, try it yourself:

编辑:它应该与INPUT一起工作(感谢指出这个Steerpike)。这是我写的测试,它有效,请亲自尝试:

<html>
<head>
  <link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
  <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.datepicker.js"></script>
  <script type="text/javascript">
  $(document).ready(function(){
    $("#datepicker").datepicker();
  });
  </script>
</head>
<body>
  <input type="text" id="datepicker" value="this is a test">   
</body>
</html>

#2


You're almost certainly not loading the datepicker plugin properly. Please supply us the code you're using to include the javascript files.

你几乎肯定没有正确加载datepicker插件。请提供您用于包含javascript文件的代码。

If you keep having problems, load the jquery and the UI from the google api.

如果您遇到问题,请从google api加载jquery和UI。

<link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("jquery", "1.3.2");
    google.load("jqueryui", "1.7.0");
</script>

#3


for me it was just case of making sure the jquery ui was the last one in the list of all the js includes.

对我而言,只是确保jquery ui是所有js包含列表中的最后一个。

#4


 $(document).ready(function(){
  // Your code here
 });

make sure your function is inside the .ready main function.

确保你的函数在.ready main函数内。

#5


It's an old post but I got here when looking for a solution so people still read it ;) I have or rather had the same problem. In my case it turned out that I was attaching js in html in wrong way (notice in what way I was ending script tag)

这是一个古老的帖子,但我在寻找解决方案时到了这里,所以人们仍然阅读它;)我已经或者更确切地说有同样的问题。在我的情况下,事实证明我以错误的方式在html中附加js(注意我以什么方式结束脚本标记)

WRONG: <script type="text/javascript" src="/fbo/js/jquery-ui-1.8.14.custom.min.js"/>

错误:

GOOD: <script type="text/javascript" src="/fbo/js/jquery-ui-1.8.14.custom.min.js"></script>

好的:

When I was doing it in the wrong way I had the same error.

当我以错误的方式做错时,我遇到了同样的错误。

#6


You are probably loading prototype.js or another library that uses $ as an alias.

您可能正在加载prototype.js或另一个使用$作为别名的库。

Try to replace $ with jQuery.

尝试用jQuery替换$。

#1


jQuery documentation says you can call the datepicker by this command:

jQuery文档说你可以通过这个命令调用datepicker:

$("#datepicker").datepicker();

If you click the 'view source' button on the documentation page you can see that they've wrapped it into the ready function:

如果单击文档页面上的“查看源”按钮,您可以看到它们已将其包装到ready函数中:

$(document).ready(function(){
    $("#datepicker").datepicker();
  });

EDIT: It should work with INPUT (thanks for pointing this out Steerpike). This is the test I've written and it works, try it yourself:

编辑:它应该与INPUT一起工作(感谢指出这个Steerpike)。这是我写的测试,它有效,请亲自尝试:

<html>
<head>
  <link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
  <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.datepicker.js"></script>
  <script type="text/javascript">
  $(document).ready(function(){
    $("#datepicker").datepicker();
  });
  </script>
</head>
<body>
  <input type="text" id="datepicker" value="this is a test">   
</body>
</html>

#2


You're almost certainly not loading the datepicker plugin properly. Please supply us the code you're using to include the javascript files.

你几乎肯定没有正确加载datepicker插件。请提供您用于包含javascript文件的代码。

If you keep having problems, load the jquery and the UI from the google api.

如果您遇到问题,请从google api加载jquery和UI。

<link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("jquery", "1.3.2");
    google.load("jqueryui", "1.7.0");
</script>

#3


for me it was just case of making sure the jquery ui was the last one in the list of all the js includes.

对我而言,只是确保jquery ui是所有js包含列表中的最后一个。

#4


 $(document).ready(function(){
  // Your code here
 });

make sure your function is inside the .ready main function.

确保你的函数在.ready main函数内。

#5


It's an old post but I got here when looking for a solution so people still read it ;) I have or rather had the same problem. In my case it turned out that I was attaching js in html in wrong way (notice in what way I was ending script tag)

这是一个古老的帖子,但我在寻找解决方案时到了这里,所以人们仍然阅读它;)我已经或者更确切地说有同样的问题。在我的情况下,事实证明我以错误的方式在html中附加js(注意我以什么方式结束脚本标记)

WRONG: <script type="text/javascript" src="/fbo/js/jquery-ui-1.8.14.custom.min.js"/>

错误:

GOOD: <script type="text/javascript" src="/fbo/js/jquery-ui-1.8.14.custom.min.js"></script>

好的:

When I was doing it in the wrong way I had the same error.

当我以错误的方式做错时,我遇到了同样的错误。

#6


You are probably loading prototype.js or another library that uses $ as an alias.

您可能正在加载prototype.js或另一个使用$作为别名的库。

Try to replace $ with jQuery.

尝试用jQuery替换$。