【发布时间】:2015-07-28 22:38:43
【问题描述】:
我正在尝试使用 jQuery 从表中捕获两个单元格的值。我的桌子是这样的:
<table id="searchByLocationResults" class="table table-hover table-striped" cellspacing="0" style="border-collapse:collapse;">
<tbody>
<tr>
<th scope="col">View Detail</th>
<th scope="col">Quantity</th>
<th scope="col" style="display:none;">Location ID</th>
<th scope="col" style="display:none;">Item Type ID</th>
</tr>
@For Each item In Model
Dim currentItem = item
@<tr>
<td><a class="btn btn-default btn-sm" onclick="viewDetails(this)">View Detail</a></td>
<td>
@Html.DisplayFor(Function(modelItem) currentItem.COUNT)
</td>
<td style="display:none;" class="locationID">
@Html.DisplayFor(Function(modelItem) currentItem.Unique_Location_ID)
</td>
<td style="display:none;" class="itemType">
@Html.DisplayFor(Function(modelItem) currentItem.Item_Type_Identifier)
</td>
</tr>
Next
</tbody>
</table>
如您所见,每一行都有一个“查看详细信息”按钮。我需要做的是在单击按钮时使用class=locationID 和class=itemType 捕获单元格中的display:none 值,仅针对单击按钮的行。我已经在堆栈上看到了多种解决方案here、here 以及其他一些解决方案。其中大部分处理的是捕获整行值。
我尝试了几个不同的脚本:
function viewDetails(clickedRow) {
var locationID = $(this).find(".selected td:.locationID").val();
alert(locationID);
和:
function viewDetails(clickedRow) {
var locationID = tr.find(".locationID").val();
alert(locationID);
以及其他一些。
如何捕获单击“查看详细信息”的行的单元格 locationID 和 itemType 的值?
【问题讨论】:
标签: javascript jquery