面对ChecxBox上的问题Checked or not event,not working propertyly

时间:2018-03-19 06:30:48

标签: javascript jquery razor

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块。

1 个答案:

答案 0 :(得分:3)

document.getElementsByClassName('chkaddress')返回集合。您必须使用以下内容指定特定索引:

document.getElementsByClassName('chkaddress')[0].checked