JavaScript Tutorial/jQuery/unbind — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 08:25, 26 мая 2010

30. To unbind all click events from all paragraphs

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


30. 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


30. 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>


30. 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>


30. 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>


30. 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>