我在列表視圖中有一個html表格,並在其中有一個名爲「vehicle_num」的隱藏標籤。我能夠得到選定的表格行,以及任何td,但我似乎無法獲得標籤的價值。我曾嘗試過:使用jquery獲取表中隱藏標籤的值?
var vehicle_number = $(this).closest('tr').children('#vehicle_num').text();
下面是listview的代碼。我如何獲得標籤的價值?
<asp:ListView ID="lvEquipmentList" runat="server" DataKeyNames="vehicle_number">
<LayoutTemplate>
<table id="table-equipment-list" class="table table-list">
<thead>
<tr>
<th scope="col" class="product-line">Product line</th>
<th scope="col" class="model-number">Model #</th>
<th scope="col" class="serial-number">Serial #</th>
<th scope="col" class="dar-status">DAR Status</th>
<th scope="col" class="ship-date">Ship Date</th>
</tr>
</thead>
<tbody>
<asp:PlaceHolder ID="ItemPlaceholder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<th scope="row" class="product-line"><div class="icon"><img src='<%#Eval("image_path")%>' onerror="this.src='assets/images/placeholder.png';" alt=""/></div> <span class="line-title"><%#Eval("product_line")%></span></th>
<td class="model-number"><%#Eval("model")%><label class="vehicle_num" hidden="hidden"><%#Eval("vehicle_number")%></label></td>
<td class="serial-number"><%#Eval("serial_number")%></td>
<td class="dar-status"><img src='<%#Eval("display_status") %>'/></td>
<td class="ship-date"><%#Eval("date")%></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<table id="table-equipment-list" class="table table-list">
<thead>
<tr>
<th scope="col" class="product-line">Product line</th>
<th scope="col" class="model-number">Model #</th>
<th scope="col" class="serial-number">Serial #</th>
<th scope="col" class="dar-status">DAR Status</th>
<th scope="col" class="ship-date">Ship Date</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row" class="product-line"><div class="icon"></div> <span class="line-title"></span></th>
<td class="model-number"></td>
<td class="serial-number"></td>
<td class="dar-status"></td>
<td class="ship-date"></td>
</tr>
</tbody>
</table>
</EmptyDataTemplate>
</asp:ListView>
EDIT
我已編輯上面的代碼把標籤在表列中。我是能夠得到使用值:
var vehicle_number = $(this).closest('tr').find('.vehicle_num').text();
'
當使用'MasterPages'時,'ASP.NET'傾向於更改'Control''ID'。 – melancia 2014-10-10 14:46:19
看看這個:[Control.ClientIDMode屬性](http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode(v = vs.110).aspx) – melancia 2014-10-10 14:47:54