[英]Getting values from a particular column in an html table
I have a controller setup and the view contains a table with some information. 我有一个控制器设置,该视图包含一个包含一些信息的表。 When the submit button is pressed on the jsp page, I would like to get the information from the 2nd column in the table so that I can process that information in the controller.
当在jsp页面上按下“提交”按钮时,我想从表的第二列中获取信息,以便可以在控制器中处理该信息。 The rows in the table can vary from 2 to 100, so I was looking for something that would get the value from the 2nd column irrespective of the number of rows.
表中的行数可以从2到100不等,因此我一直在寻找可以从第二列获取值的东西,而与行数无关。 I want to extract the information from td class urltext.
我想从td类urltext中提取信息。 I did my research but I was not able to find any information related to this so any ideas would be highly appreciated.
我进行了研究,但找不到任何与此相关的信息,因此将不胜感激任何想法。 Thanks.
谢谢。
<table name="urlTable" id="urlList" style="width:100%; overflow: scroll;">
<tr>
<th>Select</th>
<th>URL</th>
</tr>
<c:forEach var="urlList" items="${command.urlList}">
<tr>
<td><input type="checkbox" name="chk"/></td>
<td class="urlText"><input class="urlValue" type="text" value="${urlList}" style="font-size: 13px; border: none;" size="85px;" readonly="readonly"/></td>
</tr>
</c:forEach>
</table>
Let's start by using thead
and tbody
elements as we ought. 让我们从应该使用
thead
和tbody
元素开始。
<table name="urlTable" id="urlList" style="width:100%; overflow: scroll;">
<thead>
<tr>
<th>Select</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<c:forEach var="urlList" items="${command.urlList}">
<tr>
<td><input type="checkbox" name="chk"/></td>
<td class="urlText"><input class="urlValue" type="text" value="${urlList}" style="font-size: 13px; border: none;" size="85px;" readonly="readonly"/></td>
</tr>
</c:forEach>
</tbody>
</table>
Then just target the second column of each row in the tbody
. 然后将目标对准
tbody
中每一行的第二列。 I assume you're targeting the input
. 我认为您的目标是
input
。
var inputs = $("#urlList > tbody > tr > td:nth-child(2) > input");
I don't know what you want to do with the input at this point. 我目前不知道您要如何处理输入。 If you want an Array of the values, do this.
如果要使用值的数组,请执行此操作。
var vals = inputs.map(function() {
return this.value;
}).toArray();
you can try this: 您可以尝试以下方法:
var values = [];
$('#urlList .urlvalue').each(function(){
var val = $(this).val();
values.push(val);
});
The array values have all input values from your table. 数组值具有表中的所有输入值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.