实例 删除一个指定的由 on() 方法添加的点击事件处理

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
function changeSize() {
  $(this).animate({fontSize: "+=10px"});
}
function changeSpacing() {
  $(this).animate({letterSpacing: "+=5px"});
}
  
$(document).ready(function(){
  $("p").on("click", changeSize);
  $("p").on("click", changeSpacing);
  $("button").click(function(){
    $("p").off("click", changeSize);
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>Click any p element to increase size and letterspacing.</p>
<button>Remove the changeSize() event handler</button>
</body>
</html>
                    

输出结果