PHP & JavaScript Room :: 設置サンプル

実行結果

イベント操作:イベントヘルパー:click()イベントの使用例 | jQuery

▼クリックした段落を隠します。

First Paragraph

Second Paragraph

Yet one more Paragraph


▼チェックボックスを全選択・全解除します。

設置サンプルのソース

<!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" xml:lang="ja" lang="ja">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="Content-Language" content="ja" />
      <meta http-equiv="Content-Script-Type" content="text/javascript" />
      <meta http-equiv="Content-Style-Type" content="text/css" />
      <meta http-equiv="imagetoolbar" content="no" />
      <title>イベント操作:イベントヘルパー:click()イベントの使用例 | jQuery</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
      <!-- JS -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript">
         $(function(){
            $("#sample p").click(function(){
               $(this).slideUp(); 
            });
            $("#sample p").hover(function(){
               $(this).addClass("hilite");
            }, function () {
               $(this).removeClass("hilite");
            });
            
            /* 【全解除】ボタンをクリックした時に、すべてのチェックボックスのチェックを外す */
            $("#btn_on").click(function(){
                $("input[type='checkbox']").attr('checked', true);
            });
            /* 【全選択】ボタンをクリックした時に、すべてのチェックボックスを選択する */
            $("#btn_off").click(function(){
                $("input[type='checkbox']").attr('checked', false);
            });
         });
      </script>
      <style type="text/css">
         #sample p { color:red; margin:5px; cursor:pointer; }
         #sample p.hilite { background:yellow; }
      </style>
   <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
   <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP &amp; JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
      <div id="wrap">
         <h1>イベント操作:イベントヘルパー:click()イベントの使用例 | jQuery</h1>
<!-- CODE -->
         <p>▼クリックした段落を隠します。</p>
         <div id="sample">
            <p>First Paragraph</p>
            <p>Second Paragraph</p>
            <p>Yet one more Paragraph</p>
         </div>
         <br>
         <p>▼チェックボックスを全選択・全解除します。</p>
         <form id="checks" action="#">
            <p>
               <input type="button" id="btn_on" name="btn_on" value="全選択" />
               <input type="button" id="btn_off" name="btn_off" value="全解除" />
            </p>
            <p>
               <label for="c1"><input type="checkbox" id="c1" name="c1" value="1" /> 選択肢1</label>
               <label for="c2"><input type="checkbox" id="c2" name="c2" value="2" /> 選択肢2</label>
               <label for="c3"><input type="checkbox" id="c3" name="c3" value="3" /> 選択肢3</label>
            </p>
         </form>
<!-- CODE / -->
      </div>
   </body>
</html>