How can i know which radio input is selected in jQuery?
This question already has an answer here:
通过使用:
function getCheckedRadioValue(name) {
return $('input[name='+name+']:radio:checked').val();
}
You can do
$('input[type=radio]').each(function(){
if($(this).is(':checked')){
alert('this button is checked');
}
});
See the working example below:
$('button').click(function() {
var counter = 1;
$('input[type=radio]').each(function() {
if ($(this).is(':checked')) {
alert(' button ' + (counter) + ' is checked');
}
counter++;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type=radio checked />
<input type=radio />
<input type=radio checked />
<button>check</button>
链接地址: http://www.djcxy.com/p/24588.html