0
<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;}

我希望在这个数组中,在检查天数的位置为真,在不检查天数的位置为假

4

0 回答 0