jQ load方法在jquery1.8版本中被废弃,用on进行绑定

原文链接:https://blog.csdn.net/POJIE19820106/article/details/102276707

1
2
$( "" ).load( function (){
})

 

一直报错url.indexOf is not a function

函数的第一个参数为url,即字符串,indexOf属于字符串的方法,瞬间明白,传入一个函数的时候报错url.indexOf。

为什么之前用的时候可以呢?

通过查阅jQuery Blog,发现

.load, .unload, and .error, deprecated since jQuery 1.8, are no more. Use .on() to register listeners.

原来在Jquery1.8之后的版本,load方法已经被遗弃。移除原因如下:

The .load() method is an ambiguous signature, it can either be an ajax load or attach/fire a "load" event. CCAO cannot tell them apart since it's a dynamic decision based on arguments.

If .load() is being deprecated, .unload() should be as well.

因为和ajax中load方法冲突,具体可以参考这里

处理load问题的解决方案

jQuery Blog上说,通过使用on进行绑定,即如下:


$( "" ).on( 'load' , function (){
})


因为on和bind都是处理事件绑定的,经测试bind也可以。


$( "" ).bind( 'load' ,  function (){
//处理相应的事务
}).attr({
        "href"  :  'index.css' ,
        "type"  :  "text/css" ,
        "rel"   :  "stylesheet"
      }).appendTo( 'head' );

posted @   yinghualeihenmei  阅读(53)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示