不知道下面的代码是怎么回事就是不能正确的删除
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>移除事件</title>
<script src="jquery-1.3.1.js"></script>
<script>
     $(document).ready(function(){
    $("#btn").bind('click',function(e){
  $("#test").append("<p>我的绑定函数1</p>");
}).bind('click',function(){
  $("#test").append("<p>我的绑定函数2</p>");
}).bind('click',function(){
  $("#test").append("<p>我的绑定函数3</p>");
});
$("#delAll").click(function(){
  alert("进入");
  $("#btn").unbind('click');
  alert("结束");
});
 });
</script>
</head><body>
   <button id="btn">点击我</button>
   <div id="test"></div>
   <button id="delAll">删除所有</button>
</body>
</html>点击删除所有的时候,能alert出进入和结束,不知道为什么不执行,谢谢大家

解决方案 »

  1.   

    unbind只是解除了btn的click事件,但是不会删除已经添加的节点.$(document).ready(function(){
        $("#btn").bind('click',function(e){
      $("#test").append(" <p>我的绑定函数1 </p>");
    }).bind('click',function(){
      $("#test").append(" <p>我的绑定函数2 </p>");
    }).bind('click',function(){
      $("#test").append(" <p>我的绑定函数3 </p>");
    });
    $("#delAll").click(function(){
      alert("进入");
      $("#btn").unbind('click');
      //加上这句删除所有<p>节点
      $("p").remove();
      alert("结束");
    });
    }); 
      

  2.   

    triggerHandler(type,[data])
    这个特别的方法将会触发指定的事件类型上所有绑定的处理函数。但不会执行浏览器默认动作.--------------------------------------------------------------------------------This particular method triggers all bound event handlers on an element (for a specific event type) WITHOUT executing the browsers default actions.
    返回值
    jQuery参数
    type (String) : 要触发的事件类型data (Array) : (可选)传递给事件处理函数的附加参数示例
    如果你对一个focus事件执行了 .triggerHandler() ,浏览器默认动作将不会被触发,只会触发你绑定的动作。 HTML 代码:<button id="old">.trigger("focus")</button>
    <button id="new">.triggerHandler("focus")</button><br/><br/>
    <input type="text" value="To Be Focused"/> 
    jQuery 代码:$("#old").click(function(){
      $("input").trigger("focus");
    });
    $("#new").click(function(){
      $("input").triggerHandler("focus");
    });
    $("input").focus(function(){   $("<span>Focused!</span>").appendTo("body").fadeOut(1000); }); 
      

  3.   

    ls的和lz的问题有什么管理吗?