按钮获取特定输入隐藏值jQuery
我有一个表自动生成信息的表 对于每行,我都有一个按钮,该按钮又有一个输入类型='Hidden'元素:
<table>
<tr>
<td>ROW1</td>
<td>
<input type="hidden" id="id_1" value="1" />
<button class="btn btn-danger" id="bttn_1">DEL</button>
</td>
</tr>
<tr>
<td>ROW2</td>
<td>
<input type="hidden" id="id_2" value="2" />
<button class="btn btn-danger" id="bttn_2">DEL</button>
</td>
</tr>
<tr>
<td>ROW3</td>
<td>
<input type="hidden" id="id_3" value="3" />
<button class="btn btn-danger" id="bttn_3">DEL</button>
</td>
</tr>
</table>
如果我从bttn_3 ID按按钮3,则可以从隐藏的输入中获取具有ID_3 ID的值。
I have a table in which the information is generated automatically
for each line I have a button which in turn has an input type = 'hidden' element:
<table>
<tr>
<td>ROW1</td>
<td>
<input type="hidden" id="id_1" value="1" />
<button class="btn btn-danger" id="bttn_1">DEL</button>
</td>
</tr>
<tr>
<td>ROW2</td>
<td>
<input type="hidden" id="id_2" value="2" />
<button class="btn btn-danger" id="bttn_2">DEL</button>
</td>
</tr>
<tr>
<td>ROW3</td>
<td>
<input type="hidden" id="id_3" value="3" />
<button class="btn btn-danger" id="bttn_3">DEL</button>
</td>
</tr>
</table>
If I press button 3 from the bttn_3 id then I can take the value from the hidden input with the id_3 id.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样做:
$('button [id^= bttn _]')
将选择所有按钮,其中id
以> bttn _
开始。$(this).prev(“输入”)
表示我们将选择与单击按钮关联的输入。演示
You can do it like this:
$('button[id^=bttn_]')
will select all buttons where theid
starts withbttn_
$(this).prev("input")
means that we will select the input that is associated with the button clicked.Demo