Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery对表列中的所有单元格运行函数_Javascript_Jquery_Html Table - Fatal编程技术网

Javascript 使用jQuery对表列中的所有单元格运行函数

Javascript 使用jQuery对表列中的所有单元格运行函数,javascript,jquery,html-table,Javascript,Jquery,Html Table,我在下面定义了一个table元素$table。我试图在每个单元格上运行一个函数,该单元格包含由特定表标题定义的特定列-qc\u statusTh。我已经找到了该表标题的索引(qc\u statusColumnIndex),并且能够抓取该列中的下一个表单元格-qc\u statusCell) 但是,我无法循环表单元格并在该列中的每个表单元格上运行函数 以下是我到目前为止的JavaScript代码: $(文档).ready(函数(){ var$table=$(“table.tables.list”)

我在下面定义了一个table元素
$table
。我试图在每个单元格上运行一个函数,该单元格包含由特定表标题定义的特定列-
qc\u statusTh
。我已经找到了该表标题的索引(
qc\u statusColumnIndex
),并且能够抓取该列中的下一个表单元格-
qc\u statusCell

但是,我无法循环表单元格并在该列中的每个表单元格上运行函数

以下是我到目前为止的JavaScript代码:

$(文档).ready(函数(){
var$table=$(“table.tables.list”);
如果($table.length>0){
var qc_statusTh=$(“th.headersub:contains('qc_status'));
var qc_statusColumnIndex=$(qc_statusTh).index();
var qc_statusCell=$($表).find(“td”).eq(qc_statusColumnIndex);
//这不起作用。这只替换第一个单元格
//在带有“测试”的qc\U状态后的行中
$(qc_statusCell).每个(函数(){
$(本)。替换为(“测试”);
});
}
});

如何编辑此代码以循环遍历表中具有与
qc\u statusColumnIndex
相等索引的每个单元格?

如果仔细考虑,您确实希望(使用
每个
)迭代表中的行,而不是单元格。如果这样做,那么就可以从每一行抓取第n个
td
元素并应用转换

$(文档).ready(函数(){
var$table=$(“table.tables.list”);
如果($table.length>0){
var qc_statusTh=$(“th.headersub:contains('qc_status'));
var qc_statusColumnIndex=$(qc_statusTh).index();
var qc_rows=$($表).find('tr');
$(qc_行)。每个(函数(){
$(this).find('td').eq(qc_statusColumnIndex).替换为(“TESTING”);
});
}
});

qc_示例
qc_状态
1.
好啊
2.
好啊
3.
错误