Why is jqueryUI datepicker throwing an error?

…衆ロ難τιáo~ 提交于 2020-01-04 05:11:07

问题


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

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

The firebug error reads:

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

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

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

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

Nothing is executing...


回答1:


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

$("#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:

$(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:

<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.

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

<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.




回答4:


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

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




回答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)

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.

Try to replace $ with jQuery.



来源:https://stackoverflow.com/questions/713205/why-is-jqueryui-datepicker-throwing-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!