你的位置:首页 > 软件开发 > Java > [DOM Event Learning] Section 3 jQuery事件处理基础 on(), off()和one()方法使用

[DOM Event Learning] Section 3 jQuery事件处理基础 on(), off()和one()方法使用

发布时间:2015-04-01 19:02:31
[DOM Event Learning] Section 3 jQuery事件处理基础 on(),off()和one()方法使用   jQuery提供了简单的方法来向选择器(对应页面上的元素)绑定事件处理器(event handlers).  当一个事件发生,提供的fun ...

[DOM Event Learning] Section 3 jQuery事件处理基础 on(),off()和one()方法使用

  
// Tearing down all click handlers on a selection$("p").off("click");// Tearing down a particular click handler, using a reference to the functionvar foo = function () {  console.log("foo");};var bar = function () {  console.log("bar");};$("p").on("click", foo).on("click", bar);$("p").off("click", bar); // foo is still bound to the click event
   注意上面这段代码中,这个firstClick方法将在所有p元素第一次被点击的时候执行一次,而不是某个p被点击一次之后就从所有p中移除该方法.  这种情况下,所有事件的第一次执行都会进入这个处理方法.

原标题:[DOM Event Learning] Section 3 jQuery事件处理基础 on(), off()和one()方法使用

关键词:jquery

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录