编辑下面的代码:【加编码】
<html> <head> <script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p.test1").on("click",function(){ $(this).css("background-color","pink"); }); $("#btn1").click(function(){ $("p.test1").off(); }); $("p.test2").live("click",function(){ $(this).css("background-color","yellow"); }); $("#btn2").click(function(){ $("p.test2").die(); }); }); </script> </head> <body> <h4 style="color:green;">This example demonstrates how to achieve the same effect using off() and die().</h4> <p class="test1">Click this paragraph to change its background color.</p> <p class="test1">Click the button below and then click on this paragraph (the click event is removed).</p> <button id="btn1">Remove the click event with off()</button> <p class="test2">Click this paragraph to change its background color.</p> <p class="test2">Click the button below and then click on this paragraph (the click event is removed).</p> <button id="btn2">Remove the click event with die()</button> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂