问题
I'm trying to get the following code to work allowing me to use the datepicker. Whilst I have had a variation of this working previously I'm now unable to get it working after a restore.
I get the error 'Uncaught TypeError: undefined is not a function' below the line 'Modernizr.load'
<script>
Modernizr.load({
test: Modernizr.inputtypes.date,
nope: ['http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js', 'jquery-ui.css'],
complete: function () {
if (window.jQuery) {
jQuery('input[type=date]').datepicker({
dateFormat: 'yy-mm-dd'
});
}
}
});
Any suggestions as to what the cause of this error is?
回答1:
I just pasted a simple modernizr custom build in your fiddle which seems to work for firefox:
However, I had to change the way you load jquery-ui: simply replace that cdn with your desired theme:
nope: [
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css'],
....
Mins was right, here the custom build:
回答2:
Uncaught TypeError: undefined is not a function
means that you are trying to call something as a function that does not exist. In this case, you are calling several functions by reference.
Modernizr.load
, and jQuery().datepicker
. That means that either Modernizr.load
doesn't exist, in which case make sure that the Modernizr.load checkbox is checked. If it is datepicker that is causing the issue, then you need to check your developer tools network log to see if
- jQuery UI is downloading
- it is being parsed correctly (no errors are being thrown in the console for it).
Also, jQuery 1.4 is 4 and a half years old! Try and use a newer version if you can, there are a ton of speed improvements in later versions!
回答3:
The development version of Modernizr.js doesn't include load()
. To get this function you need to use the library builder and check load option in the Extra section.
The reason given by the Modernizr team:
We don't include it because it's actually a separately maintained library called yepnope - you can get it at https://github.com/slexaxton/yepnope.js
More here: Uncaught TypeError: Object # has no method 'load' #307
来源:https://stackoverflow.com/questions/23513023/uncaught-typeerror-with-modernizr-load