0
我有这个问题; 我使用的编辑器模板如下;如何为容器元素创建唯一标识号?
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SHP.WebUI.Models.OtherTeam>" %>
<fieldset>
<legend><%:Model.Approver.GetName() %> team.</legend>
<table class="groupBorder">
<tr>
<th align="right">Name</th>
<th><div>Entitlement</div><div>THIS Year</div></th>
<th><div>Days Left</div><div> THIS Year</div></th>
<th><div>Leave</div><div>Taken</div></th>
<th><div>Future</div><div>Booked</div><div>Leave</div></th>
<th><div>Days Left</div><div> NEXT Year</div></th>
<th align="center"><div style="padding-bottom:5px;">Select</div><div style="padding-left:11px;">
<input type="checkbox" id="OtherSelectAll" /></div></th>
</tr>
<tbody id="OtherSelectContainer">
<%: Html.EditorFor(model => model.TeamMembers) %>
</tbody>
<tr>
<td colspan="2" align="right">Date From</td>
<td colspan="6"><%: Html.EditorFor(model => model.CalendarVM.Dates.DateFrom) %></td>
</tr>
<tr>
<td colspan="2" align="right">Date To</td>
<td colspan="6"><%: Html.EditorFor(model => model.CalendarVM.Dates.DateTo)%>OR last holiday date <%: Html.EditorFor(model => model.CalendarVM.Dates.LastHolidayDateFlag)%></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="6" align="left"><input type="submit" value="Submit" id="btnSubmit"/></td>
</tr>
</table>
</fieldset>
<script language="javascript" type="text/javascript">
$('#OtherSelectAll').change(function() {
if ($(this).is(':checked')) {
$('#OtherSelectContainer').find('input:checkbox').attr('checked', true);
}
else {
$('#OtherSelectContainer').find('input:checkbox').removeAttr('checked');
}
});
</script>
它第一次输出它工作正常。但是之后ID冲突,因此Select All复选框不再起作用。 我需要tbody元素的ID是唯一的,并且同时实现Select All功能的jquery需要知道该ID是什么。 那我该怎么做?
但是,类名称也需要是唯一的,因为脚本需要引用Select复选框的正确容器。那我该怎么做? – arame3333
.net的一个“优点”是它想要拥有所有的元素ID,因此它可以控制一切。它表现不佳。声称自己的类名是好的,即使它们必须是唯一的,或者不是。 –
你是对的!非常感谢你。 – arame3333