I'd like to get the value
of the checked checkbox that has the radioListMode
class:
<label class="btn btn-secondary active">
<input type="radio" class="radioListMode" value="cards" checked>Cards
</label>
<label class="btn btn-secondary">
<input type="radio" class="radioListMode" value="pins">Pins
</label>
From this previous question , this is what I have tried and it is undefined
:
console.log($('input[class="radioListMode"]:checked').value);
I do not wish to add a name
because the value of this checkbox is only used for layout selection, not any data input.
既然您似乎在使用 jQuery,请坚持使用它:
$('input.radioListMode:checked').val();
使用.val()
属性
$('input[class="radioListMode"]:checked').val()
.value
不是 jQuery 函数,而是使用.val()
,如下所示:
console.log($('input[class="radioListMode"]:checked').val());
$(".yourClassName:checkbox:checked").each(function() {
console.log($(this).attr("id"));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.