jQuery on() 事件绑定 | 珊瑚贝

jQuery on() Event Binding

本问题已经有最佳答案,请猛点这里访问。


Possible Duplicate:
What’s the difference between on and live or bind?

我注意到人们提到了 jQuery 的 .on() 方法来绑定事件。我查阅了文档,它似乎是 1.7 版的新内容。我环顾四周,找不到我应该使用它的原因以及它与仅仅 .bind() 有何不同。我现在可以一直使用 .on() 还是用于特定情况?

如果有人有任何解释差异的输入或链接,我将不胜感激。


您现在可以将 on 用于所有事件绑定。正如文档所述:

As of jQuery 1.7, the .on() method provides all functionality required
for attaching event handlers.

您可以像使用 bind 一样使用它:

1
2
3
$(elem).on(“click”, function() {
    //Do stuff
});

你也可以像使用 delegate:

一样使用它

1
2
3
$(elem).on(“click”,”selector”, function() {
    //Do stuff
});

这篇博文在一定程度上讨论了它:http://blog.jquery.com/2011/09/28/jquery-1-7-beta-1-released/


来源:https://www.codenong.com/8152909/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_10105.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?