jQuery div class under div select radio button value
<div class="outer">
<div class="inner">
<input name="aa" value="aa" type="radio"/>
<input name="aa" value="bb" type="radio"/>
开发者_如何学编程 </div>
</div>
How do I get the select radio value in jQuery.
I am using this $('.outer.inner input[type="radio"]:checked')
Try this
$('.outer .inner input:radio:checked');
Working demo
The issue in your selector is .outer.inner
. This will look for both the classes on the same element. May be you missed the sapce between the 2 classes.
You should only ever have one set of radio buttons with the same name in a form, therefore you can access the selected radio button value by the name you have given the set of radio buttons. ie.
var result = $('input:radio[name=aa]:checked').val());
... or if you want the result when you change, you can use the following, again, referencing the name given to your set of radio buttons.
$('input:radio[name=aa]').change(function() {
alert($(this).val());
});
Demo
You could try to put a class to the input
<input class="myradio" name="aa" value="aa" type=radio/>
And use
$('.myradio').change(function(){
console.log($(this).val());}
);
But if you create them by code you want to use
$('.myradio').live('change', function(){
console.log($(this).val());}
);
精彩评论