我认为他们可以,但我没有把我的钱放在我的嘴(这么说)设置只读属性实际上似乎没有做任何事情。

我宁愿不使用Disabled,因为我希望选中的复选框与表单的其余部分一起提交,我只是不希望客户端能够在某些情况下更改它们。


当前回答

为什么不在上面用一个空白div覆盖输入呢?

<div id='checkbox_wrap'>
   <div class='click_block'></div>
   <input type='checkbox' /> 
</div>

然后是CSS

 #checkbox_wrap{
   height:10px;
   width:10px;
   }
 .click_block{
   height: 10px;
   width: 10px;
   position: absolute;
   z-index: 100;
}

其他回答

我会使用readonly属性

<input type="checkbox" readonly>

然后使用CSS禁用交互:

input[type='checkbox'][readonly]{
    pointer-events: none;
}

注意,使用伪类:read-only在这里不起作用。

input[type='checkbox']:read-only{ /*not working*/
    pointer-events: none;
}

你总是可以使用一个小图像,看起来像一个复选框。

<input type="checkbox" onclick="return false" />将为你工作,我正在使用这个

<input name="isActive" id="isActive" type="checkbox" value="1" checked="checked" onclick="return false"/>

很晚才开始,但我找到了MVC的答案 我禁用了复选框,并在复选框之前添加了一个HiddenFor,因此当它发布时,如果首先找到隐藏字段并使用该值。这是可行的。

 <div class="form-group">
     @Html.LabelFor(model => model.Carrier.Exists, new { @class = "control-label col-md-2" })
         <div class="col-md-10">
              @Html.HiddenFor(model => model.Carrier.Exists)
              @Html.CheckBoxFor(model => model.Carrier.Exists, new { @disabled = "disabled" })
              @Html.ValidationMessageFor(model => model.Carrier.Exists)
          </div>
 </div>