off()
- off方法如果不传递参数, 会移除所有的事件
$("div").mouseleave(function () {
alert("mouseleave");
});
$("div").mouseenter(function () {
alert("mouseenter");
$("div").off();
- off方法如果传递一个参数, 会移除所有指定类型的事件
$("div").mouseleave(function () {
alert("mouseleave");
});
$("div").mouseenter(function () {
alert("mouseenter");
$("div").off("mouseleave");
- off方法如果传递两个参数, 会移除所有指定类型的指定事件
$(“button”).off(“click”, test1);
function test1() {
alert("test1");
}
function test2() {
alert("test2");
}
$("button").click(test1);
$("button").click(test2);
$("button").off("click", test1);