简体   繁体   中英

Uncaught TypeError with Modernizr.Load

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?

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:

在此处输入图片说明

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

  1. jQuery UI is downloading
  2. 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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM