jquery 3.0 url.indexOf error

后端 未结 5 814
臣服心动
臣服心动 2020-11-27 10:24

I am getting following error from jQuery once it has been updated to v3.0.0.

jquery.js:9612 Uncaught TypeError: url.indexOf is not a function

5条回答
  •  一个人的身影
    2020-11-27 11:08

    @choz answer is the correct way. If you have many usages and want to make sure it works everywhere without changes you can add these small migration-snippet:

    /* Migration jQuery from 1.8 to 3.x */
    jQuery.fn.load = function (callback) {
        var el = $(this);
    
        el.on('load', callback);
    
        return el;
    };
    

    In this case you got no erros on other nodes e.g. on $image like in @Korsmakolnikov answer!

    const $image = $('img.image').load(function() {
      $(this).doSomething();
    });
    
    $image.doSomethingElseWithTheImage();
    

提交回复
热议问题