我有四个
HTML表,必须比较一个表中的数据和用户选择的表.我将用户选择的表ID传递给此函数,但我不知道如何遍历此表的行:
function callme(code) {
var tableName = 'table'+code;
//alert(tableName);
//How to do loop for this table?? HELP!!
$('#tableName tr').each(function() { //how to do
if (!this.rowIndex) return; // skip first row
var customerId = $(this).find("td").eq(0).html();
alert(customerId);
// call compare function here.
});
}
对于经验丰富的jQuery程序员来说,它应该是非常简单的.这是我的jsfiddle:http://jsfiddle.net/w7akB/66/
解决方法
您正在使用错误的选择器,这:
$('#tableName tr')
表示从具有id tableName的表中获取所有tr.这是你想要做的:
$('#' + tableName +' tr')
所以你将选择id存储在tableName变量中的表.