遍历< tr>传递表ID时 [英] Looping through <tr> when table ID is passed

查看:71
本文介绍了遍历< tr>传递表ID时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个HTML表,并且必须将一个表中的数据与用户选择的一个表进行比较.我正在将用户选择的表ID传递到此函数中,但是我不知道如何遍历该表的行:

I have four HTML tables and have to compare data from one table with one that is selected by the user. I am passing the user-selected table ID into this function, but I don't know how to loop through the rows of this table:

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/

It should be something very simple for a experienced jQuery programmer. Here is my jsfiddle: http://jsfiddle.net/w7akB/66/

推荐答案

您正在使用错误的选择器,这是

You are using bad selector, this:

$('#tableName tr')

表示从ID为tableName的表中获取所有tr.这就是您想要做的:

means get all tr from table with id tableName. This is what you want to do:

$('#' + tableName +' tr')

因此您将选择ID存储在tableName变量中的表.

so you will select table with id stored inside tableName variable.

这篇关于遍历< tr>传递表ID时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆