- 从jQuery 1.7开始,on()函数提供了绑定事件处理程序所需的所有功能,用于统一取代以前的bind()、 delegate()、 live()等事件函数。
- on()函数用于为指定元素的一个或多个事件绑定事件处理函数。
- off()函数
off()函数用于移除元素上绑定的一个或多个事件的事件处理函数。
off()函数主要用于解除由on()函数绑定的事件处理函数。
要删除通过on()绑定的事件,请使用off()函数。如果要附加一个事件,只执行一次,然后删除自己,请使用one()函数。
$(document).on('mouseenter', '.one', function () {
$(".a")。animate({ 'width': '1200px', 'right': '900' }, 700);
})
$(document).off("mouseenter", ".one");
$("body").off("click");// 移除body元素为所有元素的任何事件绑定的所有处理函数
// $("body").off( );
项目中使用
var wd=document.body.clientWidth;
if(wd>768){
screen();
}else{
$(document).off("mouseenter", ".one");
$(document).off("mouseenter", ".two");
$(document).off("mouseenter", ".three");
$(document).off("mouseenter", ".four");
}
window.onresize=function(){
$(document).off("mouseenter", ".one");
$(document).off("mouseenter", ".two");
$(document).off("mouseenter", ".three");
$(document).off("mouseenter", ".four");
var wd=document.body.clientWidth;
if(wd>768){
screen();
}
}