Javascript 使用jquery获取特定th列的td元素值
我有下面的htmlJavascript 使用jquery获取特定th列的td元素值,javascript,jquery,html,Javascript,Jquery,Html,我有下面的html <table border="1" class="myTable"> <tr> <th class="cname">Component</th> <th class="pname">Properties</th> <th class="sname">lqwa
<table border="1" class="myTable">
<tr>
<th class="cname">Component</th>
<th class="pname">Properties</th>
<th class="sname">lqwasb10</th>
<th class="sname">lqwasb11</th>
</tr>
<tr>
<td class="cname">InventoryManager</td>
<td class="pname">maxConcurrentUpdateRetries</td>
<td class="pvalue">1</td>
<td class="pvalue">1</td>
</tr>
<tr>
<td class="cname">CatalogTools</td>
<td class="pname">queryASAFFabrics</td>
<td class="pvalue">skuType="ASAF_FABRIC" AND NOT basicColor IS NULL ORDER BY dynamicAttributes.fabricpriceband, basicColor, dynamicAttributes.fabrictype, dynamicAttributes.asafpattern, dynamicAttributes.asaffabricbrand</td>
<td class="pvalue">skuType="ASAF_FABRIC" AND NOT basicColor IS NULL ORDER BY dynamicAttributes.fabricpriceband, basicColor, dynamicAttributes.fabrictype, dynamicAttributes.asafpattern, dynamicAttributes.asaffabricbrand</td>
</tr>
<tr>
<td class="cname">CatalogTools</td>
<td class="pname">loggingDebug</td>
<td class="pvalue">false</td>
<td class="pvalue">false</td>
</tr>
</table>
我希望b10可以按顺序包含以下值
- 一,
- skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
- 假的
非常感谢。要打印属于第三列的所有单元格,您可以选择以下单元格:
$('.myTable tr:gt(0) td:nth-child(3)')
$('.myTable tr:gt(0)td:n子级(3)')。每个(函数(){
var b10=$(this.text();
控制台日志(b10);
});代码>
组成部分
性质
lqwasb10
lqwasb11
库存经理
maxConcurrentUpdateRetries
1.
1.
目录工具
槲皮素
skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
目录工具
日志调试
假的
假的
要打印属于第三列的所有单元格,您可以选择以下单元格:
$('.myTable tr:gt(0) td:nth-child(3)')
$('.myTable tr:gt(0)td:n子级(3)')。每个(函数(){
var b10=$(this.text();
控制台日志(b10);
});代码>
组成部分
性质
lqwasb10
lqwasb11
库存经理
maxConcurrentUpdateRetries
1.
1.
目录工具
槲皮素
skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
目录工具
日志调试
假的
假的
假设您需要的列可能并不总是第三列,您可以使用:
var idx;
// Find index of cell with 'lqwasb10'
$('.myTable th').each(function(index) {
if ($(this).text() === 'lqwasb10') idx = index;
})
// Loop through each cell with the same index
$('.myTable tr').each(function() {
console.log($(this).find('td:eq('+idx+')').text())
})
var-idx;
//查找具有“lqwasb10”的单元格索引
$('.myTable th')。每个(函数(索引){
if($(this).text()=='lqwasb10')idx=索引;
})
//循环遍历具有相同索引的每个单元格
$('.myTable tr')。每个(函数(){
console.log($(this.find('td:eq('+idx+'))).text()
})
组成部分
性质
lqwasb10
lqwasb11
库存经理
maxConcurrentUpdateRetries
1.
1.
目录工具
槲皮素
skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
目录工具
日志调试
假的
假的
假设您需要的列可能并不总是第三列,您可以使用:
var idx;
// Find index of cell with 'lqwasb10'
$('.myTable th').each(function(index) {
if ($(this).text() === 'lqwasb10') idx = index;
})
// Loop through each cell with the same index
$('.myTable tr').each(function() {
console.log($(this).find('td:eq('+idx+')').text())
})
var-idx;
//查找具有“lqwasb10”的单元格索引
$('.myTable th')。每个(函数(索引){
if($(this).text()=='lqwasb10')idx=索引;
})
//循环遍历具有相同索引的每个单元格
$('.myTable tr')。每个(函数(){
console.log($(this.find('td:eq('+idx+'))).text()
})
组成部分
性质
lqwasb10
lqwasb11
库存经理
maxConcurrentUpdateRetries
1.
1.
目录工具
槲皮素
skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
skuType=“ASAF_FABRIC”而非基本颜色按dynamicAttributes.fabricpriceband、基本颜色、dynamicAttributes.fabrictype、dynamicAttributes.asafpattern、dynamicAttributes.AsafBrand为空顺序
目录工具
日志调试
假的
假的
$('.myTable tr td propval')
不是有效的选择器。什么是propval
?@j08691,现在已经编辑好了。对不起,这是个打字错误。但是代码没有起作用。有什么建议吗?您可能是指$('.myTable tr td.pvalue')
。在$('.myTable tr td pvalue')
中,jQuery搜索名为pvalue
的元素,而该元素实际上是应用于
elementyes的类。我已经尝试过了,但它正在获取所有td值。我只需要lqwasb10列下的td值。请提供更多建议。$('.myTable tr td propval')
不是有效的选择器。什么是propval
?@j08691,现在已经编辑好了。对不起,这是个打字错误。但是代码没有起作用。有什么建议吗?您可能是指$('.myTable tr td.pvalue')
。在$('.myTable tr td pvalue')
中,jQuery搜索名为pvalue
的元素,而该元素实际上是应用于
elementyes的类。我已经尝试过了,但它正在获取所有td值。我只需要lqwasb10列下的td值。请给我更多建议。谢谢@gaetanoM,你能告诉我如何迭代第th行并获得td值吗。我有servername来检查服务器,我只需要打印lqwasb10下的td值。我想动态打印td值。。谢谢Hanks@gaetanoM,你能告诉我如何遍历第行并获得td值吗。我把服务器名改成了c