2012-02-24 16 views
2

私はラジオボタングループのセットを持っています。どのグループをどのグループでチェックして、それをアレイに追加するにはどうしたらいいですか?ここで jQueryモバイルでラジオボタンの値を確認する方法は?

は、私がこれまでに思い付いたものです:

私のjqueryのコード:

<script type="text/javascript"> 
    $(function() { 

     $("#getinfo").click(function() { 

      $("input[name*=radio-choice-1]:checked").each(function() { 
       alert($(this).val()); 
      }); 

     }); 

    });  

</script> 

やラジオボタン

<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">   
<input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" /> 
<label for="radio-choice-1">Yes</label> 
<input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2" /> 
<label for="radio-choice-2">No</label> 
</fieldset> 

<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">   
<input type="radio" name="radio-choice-3" id="radio-choice-3" value="choice-3" /> 
<label for="radio-choice-3">Yes</label> 
<input type="radio" name="radio-choice-3" id="radio-choice-4" value="choice-4" /> 
<label for="radio-choice-4">No</label> 
</fieldset> 

<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">   
<input type="radio" name="radio-choice-5" id="radio-choice-5" value="choice-5" /> 
<label for="radio-choice-5">Yes</label> 
<input type="radio" name="radio-choice-5" id="radio-choice-6" value="choice-6" /> 
<label for="radio-choice-6">No</label> 
</fieldset> 

<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">   
<input type="radio" name="radio-choice-7" id="radio-choice-7" value="choice-7" /> 
<label for="radio-choice-7">Yes</label> 
<input type="radio" name="radio-choice-7" id="radio-choice-8" value="choice-8" /> 
<label for="radio-choice-8">No</label> 
</fieldset> 

<a href="#" id="getinfo">getinfo</a> 
+0

アラートが機能していませんか?または、配列にそれらを入れる方法について混乱していますか? – prodigitalson

+0

申し訳ありませんが、私は十分に明確ではありませんでした。私のアラートは機能しません – Steven

答えて

6

あなたが名前の確認]ラジオボタンを探していますテキストradio-choice-1を含んでいます。これはフルネームであるため、1つのラジオボタンになります。私はあなたが実際に望んだのは、radio-button-のテキストを含む名前のチェックされたラジオボタンだと思うので、セレクタから1を取り除くだけで動作します。

Working DEMO

+0

ありがとうアンソニー。 – Steven

3

これは、作業を行います。私は私のプロジェクトで以下のコードを使用しています。 jQuery Mobileのドキュメントに記載されているようにシンプルで単純です。

$("input[type='radio']").bind("change", function(event, ui) { 
     console.log($(this).val()); 
}); 
関連する問題