在循环中发现困难 table
Finding difficult in looping table
我想获取所有 <input>
、select 名称和 table 列内的所有数据属性。我卡住了,我的 table 循环从第 5 行开始,而不是从第 2 行开始;
var rowNo = jQuery(this).attr("data-row");
jQuery("#example1 table tbody").find('tr').each(function (key, value) {
jQuery(this).find('td').each(function (key, val) {
var tName = jQuery(this).find('input,select').attr('name');
console.log(tName);
});
});
和
<div id="example1">
<table id="Invoice">
<tbody>
<tr class="header_table">
<th></th>
<th>InvoiceNo</th>
<th>InvoiceDate</th>
</tr>
<tr class="even" name="tr_2">
<td><i class="fa fa-trash-o icon-class" data-row="2"></i></td>
<td><input data-cols="1" data-row="2" name="input_[2][InvoiceNo]" type="text"></td>
<td><input data-cols="2" data-row="2" name="input_[2][InvoiceDate]" type="text"></td>
</tr>
.....
...
</tbody>
</table>
</div>
输出
"select_[5][Supplier]"
"input_[5][Description]"
"input_[5][Serial]"
"select_[5][AssetType]"
"select_[5][PurchasePrice]"
"input_[5][PONumber]"
测试了我的 html table
jQuery("table").find('tr').each(function(key,value){
jQuery(this).find('th,td').each(function(key1,val){
console.log(key1);
});
});
我的输出为:
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.
...
...
..
来自评论
i want retrieve all td data from table
我将其翻译为 "I want to have a collection of all data in all input fields in my table"。
这看起来可能很简单:
var data = {};
jQuery("#example1 table input").each(function () {
data[this.name] = this.value;
});
这将生成一个包含键和值的对象以供进一步处理。
如果data
直接传输到服务器,就变得很简单
var data = jQuery("#example1 table").serialize();
$.post("url", data);
我想获取所有 <input>
、select 名称和 table 列内的所有数据属性。我卡住了,我的 table 循环从第 5 行开始,而不是从第 2 行开始;
var rowNo = jQuery(this).attr("data-row");
jQuery("#example1 table tbody").find('tr').each(function (key, value) {
jQuery(this).find('td').each(function (key, val) {
var tName = jQuery(this).find('input,select').attr('name');
console.log(tName);
});
});
和
<div id="example1">
<table id="Invoice">
<tbody>
<tr class="header_table">
<th></th>
<th>InvoiceNo</th>
<th>InvoiceDate</th>
</tr>
<tr class="even" name="tr_2">
<td><i class="fa fa-trash-o icon-class" data-row="2"></i></td>
<td><input data-cols="1" data-row="2" name="input_[2][InvoiceNo]" type="text"></td>
<td><input data-cols="2" data-row="2" name="input_[2][InvoiceDate]" type="text"></td>
</tr>
.....
...
</tbody>
</table>
</div>
输出
"select_[5][Supplier]"
"input_[5][Description]"
"input_[5][Serial]"
"select_[5][AssetType]"
"select_[5][PurchasePrice]"
"input_[5][PONumber]"
测试了我的 html table
jQuery("table").find('tr').each(function(key,value){
jQuery(this).find('th,td').each(function(key1,val){
console.log(key1);
});
});
我的输出为:
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.
...
...
..
来自评论
i want retrieve all td data from table
我将其翻译为 "I want to have a collection of all data in all input fields in my table"。
这看起来可能很简单:
var data = {};
jQuery("#example1 table input").each(function () {
data[this.name] = this.value;
});
这将生成一个包含键和值的对象以供进一步处理。
如果data
直接传输到服务器,就变得很简单
var data = jQuery("#example1 table").serialize();
$.post("url", data);