我有以下 HTML:
<table>
<tr><td>...</td><td><input type="hidden" name="price[1]" value="10"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[6]" value="230"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[7]" value="40"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[10]" value="10"></td><td>...</td>
</table>
我还了解到,很重要的一点是,它们存储在 table
td
中,并且最好不要将它们从表中取出。 (所以我更新了代码,使其更像真实的)
我想要的是一种通过index()
编号选择其中一个的方法,以便能够获取它们的val()
.
我知道他们的索引
是从0
到3
计数的。我想使用 index(1)
获取第二个的 val()
。
最佳答案
获取第二个隐藏输入的值:
$('input[type=hidden]:eq(1)').val()
关于jQuery:在输入隐藏数组中选择特定输入隐藏元素(按索引),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17336377/