JavaScript代码:
if (document.getElementsByClassName('chkaddress').checked) {
$('#DivCommunicationAddress').show();
}
else {
$('#DivCommunicationAddress').hide();
}
Razor查看:
@Html.CustomCheckBoxFor(Employee => Employee.IsActive, new { @class = "ui-checkbox chkaddress" })
@Html.LabelFor(Employee=>Employee.IsActive, "Same As Home Address")
当我选中复选框时,不会进入if
块。它仅转到else
块。
答案 0 :(得分:3)
document.getElementsByClassName('chkaddress')
返回集合。您必须使用以下内容指定特定索引:
document.getElementsByClassName('chkaddress')[0].checked