我有一个表格,其中有一些行,每个表格都有一个数据键值。现在我选择其中一行,并希望单击一个按钮以将此数据键值作为GET值转发。我真的不知道如何捕获这个选定的数据密钥。请求帮助。如何在点击按钮时传递单击表格行的数据键值
这里是一个小提琴:fiddle
下面是我的片段至今。
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="form-horizontal" style="margin-top:5em;">
<div class="input-group">
<input class="form-control form-control-sm" id="FunctionBookSearchForEvents" placeholder="Search for Events" style="font-size:12px;">
<button class="btn btn-sm btn-secondary" href="events.phtml?TableID=''" data-id="" style="margin-left:1em; font-size:12px;">Add Event</button>
</div>
<div id="Table">
<table class="table table-sm table-hover">
<thead>
<tr>
<th>ID</th>
<th>Event Name</th>
</tr>
</thead>
<tbody>
<tr class="clickable-row" data-key="12">
<td>12</td>
<td>Test Event 12</td>
</tr>
<tr class="clickable-row" data-key="13">
<td>13</td>
<td>Test Event 13</td>
</tr>
</tbody>
</table>
</div>
</div>
但我想单击该按钮并将数据密钥与我的href网址一起传递。 – Cyber
数据键是选定行的ID吗? –
是的,基本上是这样,因为所有的数据密钥都是唯一的。 – Cyber