Datepicker报错‘datepicker is not defined’问题求助
Fixing "datepicker is not defined" Error in jQuery UI Datepicker
Hey there! That error is popping up because even though you’ve included the jQuery UI stylesheet, you haven’t loaded the jQuery UI JavaScript library—the datepicker widget is a core part of jQuery UI, so the JS file is absolutely required to make it work.
Here’s your fixed code with the missing piece added, and I’ve made sure the version matches your existing CSS to avoid compatibility hiccups:
<html lang="en"> <head> <link rel="stylesheet" href="https://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css"> </head> <body> <div id="datepicker"></div> <!-- Add jQuery UI JavaScript (matches your CSS version) --> <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script> <script> var min=3; switch (new Date().getDay()) { case 4: min = 5; break; case 5: min = 4; break; case 6: min = 3; break; } $( "#datepicker" ).datepicker({ minDate: min, beforeShowDay: $.datepicker.noWeekends }); </script> </body></html>
Key Changes Explained:
- Added the
jquery-ui.min.jsfile (version 1.9.2) — this is what defines thedatepicker()method you’re trying to use. - Placed the jQuery UI script before your custom code, so the datepicker functionality is already loaded when your script runs.
One quick check: Since you said your page already loads jQuery, just make sure jQuery itself loads before the jQuery UI script (this is usually the case if jQuery is included early in your page, but it’s worth verifying if you still hit snags).
内容的提问来源于stack exchange,提问作者John D
相关产品推荐
相关产品推荐

