我有一个转发器,其中每个项目都包含一个复选框和一个日期;它允许用户选择一组日期。提交后,我想检查所选日期是否连续(客户端)。我可以使用分配给复选框和日期的类(作为标签)来访问每个转发器项目,但不确定如何检查复选框是否已选中。
到目前为止,这是我所拥有的(我删除了不相关的内容):
<ItemTemplate>
<tr>
<td >
<asp:Checkbox runat="server" ID="cbSelectedDate" CssClass="partialCB" />
</td>
<td>
<asp:Label runat="server" ID="lblDate" CssClass="partialDate" Text='<%# Eval("DATE_STR")%>' ></asp:Label>
</td>
<td>
<asp:CheckBox runat="server" ID="cbHoliday" Checked='<%# Eval("ISHOLIDAY")%>' Enabled="false" ></asp:CheckBox>
</td>
</tr>
</ItemTemplate>
上面在页面上呈现如下:
<td>
<span class="partialCB"><input id="ctl00_MainContent_rptSchedule_ctl01_cbSelectedDate" type="checkbox" name="ctl00$MainContent$rptSchedule$ctl01$cbSelectedDate" /></span>
</td>
<td>
<span id="ctl00_MainContent_rptSchedule_ctl01_lblDate" class="NormalSmall partialDate">3/15/2019</span>
</td>
单击“提交”按钮时,将调用以下验证功能:
function validSubmission() {debugger
var isValid = true;
// a bunch of vars and other stuff
isValid = getPartialDates();
return isValid;
}
function getPartialDates() {
var spans = document.getElementsByTagName('span');
var l = spans.length;
// Iterate through spans
for (var i = 0; i < l; i++) {
var spanClass = spans[i].getAttribute("class");
// checkboxes in repeater have class "partialCB"
if (spanClass === "partialCB") {
var v = spans[i].innerHTML;
// How do I do this? innerHTML has checkbox tag
if (checkbox is checked) {
var selDate = spans[i + 1].innerText;
}
}
}