Uncaught TypeError with Modernizr.Load

天大地大妈咪最大 提交于 2020-01-15 08:39:11

问题


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

  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!




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

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