我正在尝试更改有关是否选中复选框的 TextBoxFor 只读属性。我已阅读其他帖子,但答案似乎对我不起作用。我请任何人指出我在下面的代码中错过的内容。
<div class="editor-label">
@Html.LabelFor(m => m.AddFitbit)
</div>
<div class="editor-field" id="checkBox">
@Html.CheckBoxFor(m => m.AddFitbit)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Mail)
</div>
<div class="editor-field" id="userMail">
@Html.TextBoxFor(m => m.Mail)
</div>
<br />
<input class="submit" type="submit" value="@LangResources.Create" />
<button onclick="history.back(); return false;">@LangResources.BtnCancel</button>
</div>
</article>
}
@Html.ValidationSummary(true, LangResources.ScreenAddGeneralError)
<script type="text/javascript">
$(function() {
$('#checkBox').change(function () {
if ($(this).is(':checked')) {
$('#userMail').attr('readonly');
} else {
$('#userMail').removeAttr('readonly');
}
});
});
</script>