<script type="text/javascript">
function LoadHiddenCheckBoxes() {
var hdncheckbox = document.getElementById('hdnWeekDays')
var checkbox0 = document.getElementById('sunday')
hdncheckbox[0] = checkbox0.checked;
var checkbox1 = document.getElementById('monday')
hdncheckbox[1] = checkbox1.checked;
var checkbox2 = document.getElementById('tuesday')
hdncheckbox[2] = checkbox2.checked;
var checkbox3 = document.getElementById('wednesday')
hdncheckbox[3] = checkbox3.checked;
var checkbox4 = document.getElementById('thursday')
hdncheckbox[4] = checkbox4.checked;
var checkbox5 = document.getElementById('friday')
hdncheckbox[5] = checkbox5.checked;
var checkbox6 = document.getElementById('saturday')
hdncheckbox[6] = checkbox6.checked;
}
这是我的JS
@Html.HiddenFor(model => model.weekDays, new { id = "hdnWeekDays" })
<input type="checkbox" id="sunday" style="float: left;" onchange="LoadHiddenCheckBoxes()" />
我还有一个hiddenfor来绑定模型中的数据。 weekDays定义为
[DataMember]
public bool[] weekDays {get; set;}
并且我希望在检查日期的位置使用此数组为true,而在未检查日期的情况下为false