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