禁用复选框
问题描述:
我有三个复选框。如果一个复选框被启用,我想禁用其他两个复选框。我如何使用JQuery和HTML来实现它?禁用复选框
我要实现它在MVC 4
Forenoon @Html.CheckBoxFor(x => x.FromDateforenoon, new {
style = "width:auto;",
id = "chkFromDate",
@onchange = "CalculatedaysOfLeave();"
})
Afternoon @Html.CheckBoxFor(x => x.FromDateafternoon, new {
style = "width:auto;",
id = "chkAfternoon",
@onchange = "CalculatedaysOfLeave();"
})
FullDay @Html.CheckBoxFor(x => x.FromDateFullDay, new {
style = "width:auto;",
id = "chkFullDay",
@onchange = "CalculatedaysOfLeave();"
})
答
if (document.getElementById('idofcheckBox1').disabled == false) {
document.getElementById('idofcheckBox2').disabled = true;
document.getElementById('idofcheckBox3').disabled = true;
}
由此您可以轻松实现这
https://jsfiddle.net/7LnwbyLa/?utm_source=website&utm_medium=embed&utm_campaign=7LnwbyLa
答
的Jquery:
$("input[type=checkbox]").change(function()
{
$("input[type=checkbox]").prop('checked',false);
$(this).prop('checked',true);
});
注:给人以事件和财产适当父设置
感谢您对我想要做的javascript.How我可以实现answers.If? –
Mussaib Siddiqui的答案是纯粹的JavaScript。但你用jquery lol标记了这个问题 – Luke