如何重写jQuery事件处理程序?
使用该off()方法重写jQuery事件处理程序。此方法用于删除事件处理程序。该on()方法用于附加一个或多个事件处理程序。
示例
您可以尝试运行以下代码,以了解如何覆盖jQuery事件处理程序-
<html>
<head>
<title>jQuery off() method</title>
<script src = "https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
function aClick() {
$("div").show().fadeOut("slow");
}
$("#bind").click(function () {
$("#theone").on("click", aClick).text("可以点击!");
});
$("#unbind").click(function () {
$("#theone").off("click", aClick).text("Does nothing...");
});
});
</script>
<style>
button {
margin:5px;
}
button#theone {
color:red;
background:yellow;
}
</style>
</head>
<body>
<button id = "theone">Does nothing...</button>
<button id = "bind">Bind Click</button>
<button id = "unbind">Unbind Click</button>
<div style = "display:none;">Click!</div>
</body>
</html>热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便