jQuery中.bind() .live() .delegate() .on()的区别
来源:互联网 发布:oracl 显示所有数据库 编辑:程序博客网 时间:2024/05/20 11:25
bind(type,[data],fn) 为每个匹配元素的特定事件绑定事件处理函数
$("a").bind("click",function(){alert("ok");});
live(type,[data],fn) 给所有匹配的元素附加一个事件处理函数,即使这个元素是以后再添加进来的
$("a").live("click",function(){alert("ok");});
delegate(selector,[type],[data],fn) 指定的元素(属于被选元素的子元素)添加一个或多个事件处理程序,并规定当这些事件发生时运行的函数
$("#container").delegate("a","click",function(){alert("ok");})
on(events,[selector],[data],fn) 在选择元素上绑定一个或多个事件的事件处理函数
差别:
.bind()是直接绑定在元素上
.live()则是通过冒泡的方式来绑定到元素上的。更适合列表类型的,绑定到document DOM节点上。和.bind()的优势是支持动态数据。
.delegate()则是更精确的小范围使用事件代理,性能优于.live()
.on()则是最新的1.9版本整合了之前的三种方式的新事件绑定机制
//div是页面已经有的元素,button是js生成的未来元素!
$(
"div"
).delegate(
"button"
,
"click"
,
function
(){
$(
"p"
).slideToggle();
});
$(document).on(
'click'
,
'td a'
,
function
() {
alert(
"Aha!"
);
});
1
2
3
$(
"body"
).delegate(
"td"
,
"click"
,
function
(){
alert(
"ok!"
);
});
阅读全文
0 0
- JQuery五:jQuery中.bind() .live() .delegate() .on()的区别
- jQuery 中bind(),live(),delegate(),on() 区别
- jQuery 中bind(),live(),delegate(),on() 区别
- jQuery 中bind(),live(),delegate(),on() 区别
- jQuery 中bind(),live(),delegate(),on() 区别
- jQuery 中bind(),live(),delegate(),on() 区别
- jQuery 中bind(),live(),delegate(),on() 区别
- jQuery 中bind(),live(),delegate(),on() 区别
- JQuery 中bind(),live(),delegate(),on() 区别
- jQuery中.bind() .live() .delegate() .on()区别
- jQuery中.bind() .live() .delegate() .on()区别
- jquery中bind,live,delegate和on的区别
- jQuery中.bind() .live() .delegate() .on()的区别
- jQuery中.bind() .live() .delegate() .on()的区别
- jQuery中.bind() .live() .delegate() .on()的区别
- jQuery中.bind() .live() .delegate() .on()的区别
- jQuery中.bind() .live() .delegate() .on()的区别
- jQuery中.bind() .live() .delegate() .on()的区别
- java复习-异常+断言
- 分页技术
- 当你在浏览器里输入一个网址时发生了什么
- 拷贝构造函数
- git切换分支
- jQuery中.bind() .live() .delegate() .on()的区别
- 微信小程序 3----表单组件
- YARN工作流程(MapReduce提交应用程序)
- 计算机启动过程
- Python笔记——Python基础、numpy基础、SciPy、Matplotlib
- Java8:Lambda表达式增强版Comparator和排序
- 理解 Python 装饰器看这一篇就够了
- 解读前端开发工程师必备技能
- Tomcat的热部署(以后就不用重起了)