当前位置: 首页 > 工具软件 > Live.js > 使用案例 >

关于jquery使用live()方法的问题Uncaught TypeError: $(...).live is not a function

黄成荫
2023-12-01

一、出问题原因

在维护旧项目的时候,出现浏览器控制台报错Uncaught TypeError: $(...).live is not a function

Uncaught TypeError: $(...).live is not a function
    at HTMLDocument.eval (eval at <anonymous> (jquery-1.11.3.js:339), <anonymous>:17:41)
    at fire (jquery-1.11.3.js:3148)
    at Object.add [as done] (jquery-1.11.3.js:3194)
    at jQuery.fn.init.jQuery.fn.ready (jquery-1.11.3.js:3428)
    at jQuery.fn.init (jquery-1.11.3.js:2868)
    at jQuery (jquery-1.11.3.js:73)
    at eval (eval at <anonymous> (jquery-1.11.3.js:339), <anonymous>:3:2)
    at eval (<anonymous>)
    at jquery-1.11.3.js:339
    at Function.globalEval (jquery-1.11.3.js:340)

二、修改和说明

1、说明

on() 方法在被选元素及子元素上添加一个或多个事件处理程序。
自 jQuery 版本 1.7 起,on() 方法是 bind()、live() 和 delegate() 方法的新的替代品。该方法给 API 带来很多便利,我们推荐使用该方法,它简化了 jQuery 代码库。
注意:使用 on() 方法添加的事件处理程序适用于当前及未来的元素(比如由脚本创建的新元素)。
提示:如需移除事件处理程序,请使用 off() 方法。
提示:如需添加只运行一次的事件然后移除,请使用 on() 方法。
2、修改

在项目中所有使用jquery的live()方法都修改成on()方法,使用方法相同,只用修改方法名即可。


 类似资料: