2017-07-31 14 views
1

$("input[type=radio][name=test]").val()のようにiCheck無線値を名前で取得する方法は?それは動作していないようだ。 JSFiddleをご覧ください。セレクタは、配列を返しますのでですJavascript:名前でiCheck無線値を取得する

HTML

<div class="i-checks"><label> <input type="radio" checked="" value="a" name="test"> a </label></div> 
<div class="i-checks"><label> <input type="radio" value="b" name="test"> b </label></div> 
<div class="i-checks"><label> <input type="radio" value="c" name="test"> c </label></div> 


The <span id='outputbythis' style='color:green'></span> is checked by $(this).val() 
<br> 
The <span id='outputbyname' style='color:red'></span> is checked by $("input[type=radio][name=test]").val() 

JS

答えて

1

jQuery(document).ready(function ($) { 

    $('input').iCheck({ 
     checkboxClass: 'icheckbox_flat-green', 
     radioClass: 'iradio_flat-green' 
    }); 



    $('input').on('ifToggled', function (event) { 

     $("#outputbythis").text($(this).val()) 

     $("#outputbyname").text($("input[type=radio][name=test]:checked").val()) 

    }); 

}); 

これは

+0

がどのように名前でiCheckラジオ値を取得するために動作するはず? – WCMC

+0

私の返信をチェックして、私はそれを更新しました – Klajdi

+0

ありがとう!自己学習者がそれを理解することは本当に難しい。時には '$(" input [type = radio] [name = test] ")'が持っていることがありますが、時には$( "input = type = radio" [name = test] '$(" input [type = radio] [name = test]:checked ")。val()'に変更されます。 – WCMC

関連する問題