下面的函数采用您要匹配的列号、应匹配的文本以及如果匹配则必须返回值的 returnColumn。
columnMatch:要查找
matchText文本的列号:要匹配的文本
returnColumn:如果匹配,则要从中返回文本的列号
function getMatchesFromTable(matchColumn,matchText,returnColumn)
{
var matchedValues = [];
$("table tr td:nth-child("+matchColumn+")").each(function () {
if($(this).text() == matchText){
matchedValues.push($(this).parent().find('td:nth-child('+returnColumn+')').text());
}
});
return matchedValues;
}
您可以致电的案例示例:
getMatchesFromTable(3,"Seafood",5);
这将返回类别为 Seafood 的所有元素的数组
我试图编写一个通用函数来匹配所有用例。这仍然可以根据您的要求进行更多扩展,例如在匹配的行中返回多列、匹配不区分大小写等。您可以修改此基本功能以向其添加更多功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句