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

実行結果

非同期通信:その他:serializearray()の使用例 | jQuery

▼フォーム要素をクリックしてください。フォーム要素の値を取得し、それを文字列に変換した結果を表示します。

結果:

設置サンプルのソース

<!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>非同期通信:その他:serializearray()の使用例 | 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(){
            function showValues() {
               var fields=$(":input").serializeArray();
               $("#res").empty();
               $.each(fields, function(i, field){
                  $("#res").append(field.value + " ");
               });
            }
            $(":checkbox, :radio").click(showValues);
            $("select").change(showValues);
            showValues();
         });
      </script>
      <style type="text/css">
         form { margin:5px; }
           #res { color:red; }
  </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>非同期通信:その他:serializearray()の使用例 | jQuery</h1>
         <p>▼フォーム要素をクリックしてください。フォーム要素の値を取得し、それを文字列に変換した結果を表示します。</p>
<!-- CODE -->
         <p><strong>結果:</strong> <span id="res"></span></p>
         <form>
            <p>
               <select name="single"><option>Single</option><option>Single2</option></select>
            </p>
            <p>
               <select name="multiple" multiple="multiple"><option selected="selected">Multiple</option><option>Multiple2</option><option selected="selected">Multiple3</option></select>
            </p>
            <p>
               <label for="ch1"><input type="checkbox" name="check" value="check1" id="ch1" />check1</label>
               <label for="ch2"><input type="checkbox" name="check" value="check2" checked="checked" id="ch2" />check2</label>
               <label for="r1"><input type="radio" name="radio" value="radio1" checked="checked" id="r1" />radio1</label>
               <label for="r2"><input type="radio" name="radio" value="radio2" id="r2" />radio2</label>
            </p>
         </form>
<!-- CODE / -->
      </div>
   </body>
</html>