JavaScript DHTML/jQuery/unbind

Материал из Web эксперт
Версия от 07:24, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

To unbind all click events from all paragraphs

 
$("p").unbind( "click" )



To unbind just one previously bound handler, pass the function in as the second argument:

 

var foo = function () {
  // event handler
};
$("p").bind("click", foo); // foo is binded
$("p").unbind("click", foo); // foo is no longer binded



Unbind all events from

    
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    
        $(document).ready(function(){
               $("div").unbind()
        });
    </script>

  </head>
  <body>
    <body>
       <div><h1>header 1</h1></div>
    </body>
</html>



Unbind all live events from all paragraphs

    
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    
        $(document).ready(function(){
              $("div").die();

        });
    </script>

  </head>
  <body>
    <body>
       <div><h1>header 1</h1></div>
    </body>
</html>



Unbind event

    
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    
        $(document).ready(function(){
               function aClick() {
                  $("div").show().fadeOut("slow");
               }
               $("div").click(function () {
                  $("div").unbind("click", aClick).text("Does nothing...");
               });


        });
    </script>

  </head>
  <body>
    <body>
       <div><h1>header 1</h1></div>
    </body>
</html>



unbind(type , data ): Without any arguments, all bound events are removed.

 
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                
            function aClick() {
              alert("action");
            }
            $("#bind").click(function () {
              $("#myButton").click(aClick).text("Binded");
            });
            $("#unbind").click(function () {
              $("#myButton").unbind("click", aClick).text("Not Binded");
            });
        });
    </script>
  </head>
  <body>
    <body>
          <button id="myButton">Not Binded</button>
          <button id="bind">Bind Click</button>
          <button id="unbind">Unbind Click</button>
       
                         
    </body>
</html>