$.datepicker not defined

2019-08-22 04:36发布

问题:

I cannot coax the datetimepicker to work. Datepicker works fine. But the add-on has not worked after about 7 hours of attempts.

Firebug shows no 404's.

All jQuery libraries are included with the theme framework as well.

I tried replacing all instances of $.datepicker with jQuery.datepicker in the script. This made no difference.

I tried moving scripts above or below or combining them. The same error persists. I have examined several related answers in this forum and many, many others to no avail. I have reviewed jQuery literature but it does not address this specific problem..

My code is this. Just a couple of html inputs. Datepicker works fine.

   `jQuery(document).ready(function(){
    jQuery('#datepicker').datepicker();
});

jQuery(document).ready(function(){
    jQuery('#datetime').datetimepicker();
});`

This segment of code works fine. Datetimepicker then hits the line

$.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {

$.datepicker not defined.

If you do not know the answer, perhaps there is a way for javascript/jQuery to produce more detailed information about its failures?

回答1:

Change to this

jQuery(document).ready(function(){
        $.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings){};
});

Looks like you are trying to call the function before it gets loaded. Jquery will go through each doc.ready function in order, so as long as this is after the initial load it should work.

Also, use chrome's built in develop tools for debugging purposes. Ctrl-shift-j on a PC will open them up, you can see the console messages to figure out whats going on.

heres a jsfiddle to show the working syntax http://jsfiddle.net/XA79k/



回答2:

( function($$) {


$$(document).ready(function(e) {
        $.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
});

} ) ( jQuery );

I had similiar issues and had to do it this way since there was conflicts. And I tried jQuery.noConflict() aswell, but didnt work. Above code worked for me.