1.获取选中的radio的值方法
$('input:radio:checked').val();
$("input[type='radio']:checked").val();
$("input[name='UnitProperty']:checked").val();2.获取选中的checkbox的值方法
var EducationalTrends = ''; //教育趋势
$("input[type=checkbox]:checked", $("#EducationalTrends")).each(function () {
if (EducationalTrends != '') {
EducationalTrends += ",";
}
if ($(this).parent().find("input[type='text']").length > 0) {
if ($(this).parent().find("input[type='text']").val().replace(/^\s+|\s+$/g, '') == '') {
EducationalTrends += "其他(未注明)";
}
else {
EducationalTrends += "其他" + $(this).parent().find("input[type='text']").val().replace(/^\s+|\s+$/g, '');
}
}
else {
EducationalTrends += $(this).val();
}
alert(EducationalTrends);
});
本文介绍了如何使用jQuery的选择器来获取网页中被选中的radio按钮和checkbox的值。对于radio按钮,可以直接通过`:checked`选择器结合`val()`方法获取;而对于checkbox,则需要遍历所有选中的项并将值串联起来。
443

被折叠的 条评论
为什么被折叠?



