禁用复选框

时间:2016-09-28 12:23:38

标签: javascript jquery html asp.net asp.net-mvc

我有三个复选框。如果启用了一个复选框,我想禁用其他两个复选框。如何使用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();" 
})

2 个答案:

答案 0 :(得分:0)

<强> Jquery的:

$("input[type=checkbox]").change(function()
{
    $("input[type=checkbox]").prop('checked',false);
    $(this).prop('checked',true);
});

注意:为正确的父级提供事件和属性集

答案 1 :(得分:-1)

  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