Jquery 复选框是否在mvc中选中
通过这一点,我们可以在DDL中获得所选的值。与此相同,我们如何才能得到天气复选框是否选中。我该怎么做Jquery 复选框是否在mvc中选中,jquery,model-view-controller,checkbox,checked,Jquery,Model View Controller,Checkbox,Checked,通过这一点,我们可以在DDL中获得所选的值。与此相同,我们如何才能得到天气复选框是否选中。我该怎么做 $("#Month option:selected").val(); 是否选中此复选框?要检查复选框是否选中,可以尝试使用.is(),如下所示:- jQuery语法 <input id="Baruc" type="checkbox" value="true" name="Baruc" data-val-required="The Baruc field is required." d
$("#Month option:selected").val();
是否选中此复选框?要检查复选框是否选中,可以尝试使用
.is()
,如下所示:-
jQuery语法
<input id="Baruc" type="checkbox" value="true" name="Baruc" data-val-required="The Baruc field is required." data-val="true" onchange="showlabel();">
编辑:-选中前必须有冒号
Javascipt语法
$('#Baruc').is(':checked') // it returns bool if checkbox is checked it will return 'true' otherwise 'false'.
解决方案1: 对于选中的元素,需要使用
.length
if(document.getElementById("Baruc").checked)
{
//checkbox is checked
}
解决方案2:
您还可以将.is()
方法与:checked
选择器一起使用:
if($("#Baruc:checked").length){
//checkbox is checked
}
用这个
if($("#Baruc").is(":checked")){
//checkbox is checked
}
您可以在onchange函数中传递此:
$('#Baruc').is('checked');
现在,在您的方法中,您可以使用以下内容:
onchange="showlabel(this);
函数showlabel(elem){alert(elem.checked);}
您可以检查给定代码是否选中了复选框:
function showlabel(elem){
alert(elem.checked); // true if checked false if unchecked
}
如果有任何混淆,请使用以下链接:
可能存在的副本
$(‘#CHECKBOXID’).is(‘:checked’);