我是 jQuery 和 jsp、jSTL 的新手,对于这个可能微不足道的问题感到抱歉。我在jsp中有以下代码:
<ct:thead>
<ct:th>
<ct:checkbox styleClass="toggleCheckbox"/>
</ct:th>
<ct:th><ct:message messageKey="documentID"/></ct:th>
渲染后的 html 如下:
<tr>
<td>
<span class="checkboxGroup">
<input type="checkbox">
</span>
<input name="documentID" type="hidden" value="6">
</td>
<td>6</td>
我想收集使用 jQuery 选择的所有 documentID
。它会是什么样子?提前致谢!
最佳答案
您可以使用attribute equals selector根据名称属性值进行选择。
$('[name="documentID"]')
$('[name="documentID"]').each(function() {
console.log(this.value);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>
<span class="checkboxGroup">
<input type="checkbox">
</span>
<input name="documentID" type="hidden" value="6">
</td>
<td>6</td>
</tr>
</table>
关于javascript - jsp:使用 jQuery 收集所有选定的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41781305/