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

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


当前回答

这里的一些答案似乎有点迂回,但这里有一个小技巧。

<form id="aform" name="aform" method="POST">
    <input name="chkBox_1" type="checkbox" checked value="1" disabled="disabled" />
    <input id="submitBttn" type="button" value="Submit" onClick='return submitPage();'>
</form>​

然后在jquery中,你可以选择以下两个选项之一:

$(document).ready(function(){
    //first option, you don't need the disabled attribute, this will prevent
    //the user from changing the checkbox values
    $("input[name^='chkBox_1']").click(function(e){
        e.preventDefault();
    });

    //second option, keep the disabled attribute, and disable it upon submit
    $("#submitBttn").click(function(){
        $("input[name^='chkBox_1']").attr("disabled",false);
        $("#aform").submit();
    });

});

演示: http://jsfiddle.net/5WFYt/

其他回答

在提交表单时,我们实际上传递的是复选框的值,而不是状态(选中/未选中)。只读属性阻止我们编辑值,但不能编辑状态。如果您希望使用一个只读字段来表示要提交的值,请使用只读文本。

我会使用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;
}

这适用于我的Chrome浏览器:

<input type="checkbox" onclick="return false">

只读对<input type='checkbox'>无效

所以,如果你需要从表单中禁用的复选框中提交值,你可以使用jQuery:

$('form').submit(function(e) {
    $('input[type="checkbox"]:disabled').each(function(e) {
        $(this).removeAttr('disabled');
    })
});

通过这种方式,在提交表单时从元素中删除禁用属性。

@ (Model.IsEnabled) 使用此条件进行动态检查和取消检查,如果复选框已选中,则设置为只读。

 <input id="abc" name="abc"  type="checkbox" @(Model.IsEnabled ? "checked=checked onclick=this.checked=!this.checked;" : string.Empty) >