.bind() / .unbind() ——为元素绑定 / 删除绑定事件
一、.bind()——为元素绑定事件
写法:元素.bind(事件名称,传递数据,处理函数)
$(".aa").bind("click",function(){
$(this).next().show();
});
参数:
参数1:事件名称,click等,也可以是自定义的参数
参数2:event.date属性值传递给事件对象的额外数据对象,可选参数
参数3:绑定的处理函数
调用次数:可调用多次
一次性绑定多个事件写法:
$("div").bind("mouseover mouseout", function () {
$(this).toggleClass("over");
});
//或者
$("div").bind("mouseover", function () {
$(this).toggleClass("over");
}).bind("mouseover", function () {
$(this).toggleClass("over");
});
二、.unbind()——删除绑定事件
写法:元素.unbind(事件名称)
$("div").unbind("click");
注意:绑定事件、删除绑定事件还有命名空间的写法,没整理,在jquery书的119页

浙公网安备 33010602011771号