Jquery-effect-toggle-switch

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

jQueryエフェクト-toggle(switch)メソッド

説明

  • toggle(switch)*メソッドは、渡されたパラメーターに基づいて、一致した要素のセットのそれぞれを表示します。 trueパラメーターがすべての要素を表示する場合、falseはすべての要素を非表示にします。

構文

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

selector.toggle( switch );

パラメーター

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

  • switch -ディスプレイをオンに切り替えるスイッチ。

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

<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() {

            $("#false").click(function(){
               $(".target").toggle(false);
            });

            $("#true").click(function(){
               $(".target").toggle(true);
            });

         });
      </script>

      <style>
         p {background-color:#bca; width:250px; border:1px solid green;}
      </style>
   </head>

   <body>
      <p>Click on any of the following buttons:</p>

      <button id = "false"> False Switch </button>
      <button id = "true"> True Switch </button>

      <div class = "target">
         <img src = "../images/jquery.jpg" alt = "jQuery"/>
      </div>
   </body>
</html>

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