EditorFor复选框始终返回false

时间:2013-12-09 15:04:13

标签: jquery checkbox

HTML:

   <div class="editor-label">
    <%: Html.LabelFor(model => model.IsFeatured)%>
</div>
<div id="IsFeatured" class="editor-field textbox">
    <%: Html.EditorFor(model => model.IsFeatured)%>
    <%: Html.ValidationMessageFor(model => model.IsFeatured)%>

jQuery的:

var IsFeatured = $('#IsFeatured').is(':checked'); 
alert('IsFeatured= '+IsFeatured);

如果选中复选框,我总是会弄错。

this doesnt help

neither does this

1 个答案:

答案 0 :(得分:1)

因为#IsFeatured是div而不是复选框,请尝试

var IsFeatured = $('#IsFeatured input[type="checkbox"]').is(':checked');