求问jQuery中delegate 和on的区别?
phpcn_u233
phpcn_u233 2017-03-04 14:56:12
0
2
2033

// jQuery 1.4.3+
$( elements ).delegate( selector, events, data, handler );
// jQuery 1.7+
$( elements ).on( events, [selector], data, handler );

求问 delegate 和on的区别只是参数顺序吗?如果只是参数顺序的话,觉得没必要去更新方法哈


phpcn_u233
phpcn_u233

reply all(2)
数据分析师

What is the difference between delegate and on in jQuery? -PHP Chinese website Q&A-What is the difference between delegate and on in jQuery? -PHP Chinese website Q&A

Let’s take a look and learn.

阿神

官方文档已经不推荐使用.delegate()了

.delegate() has been deprecated. It was superseded by the .on() method since jQuery 1.7, so its use was already discouraged.

更新答案,题主举的例子中,结果是一样的:

.on() 的语法有两种情况:

1.此时效果跟.bind()、.click()是一样的。

目标元素.on('click',handler);

2.而下面这种情况,确实跟 .delegate()是一样的。          

代理元素.on('目标元素选择器',handler);


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template