Jquery-events-unbind

提供:Dev Guides
移動先:案内検索

jQuery-unbind([type]、[fn])メソッド

説明

  • unbind([type]、[fn])*メソッドはバインドの反対を行い、一致した各要素からバインドされたイベントを削除します。

構文

このメソッドを使用するための簡単な構文は次のとおりです-

selector.unbind( [type], [fn] )

パラメーター

これは、この方法で使用されるすべてのパラメータの説明です-

  • type -スペースで区切られた1つ以上のイベントタイプ。
  • fn -一致した要素の各セットでイベントからバインド解除する関数。

以下は、このメソッドの使用方法を示す簡単な例です-

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript"
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>

      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {

            function aClick() {
               $("div").show().fadeOut("slow");
            }

            $("#bind").click(function () {
               $("#theone").click(aClick).text("Can Click!");
            });

            $("#unbind").click(function () {
               $("#theone").unbind('click', aClick).text("Does nothing...");
            });

         });
      </script>

      <style>
         button { margin:5px; }
         button#theone { color:red; background:yellow; }
      </style>
   </head>

   <body>
      <button id = "theone">Does nothing...</button>
      <button id = "bind">Bind Click</button>
      <button id = "unbind">Unbind Click</button>

      <div style = "display:none;">Click!</div>
   </body>
</html>

これにより、次の結果が生成されます–