逐行获取表索引jquery

时间:2014-07-29 11:58:44

标签: jquery

我想使用行索引访问表格中的行。

当我尝试获取行时索引我得到:

Uncaught TypeError: undefined is not a function 

这是我的代码:

function moveUpMuscle(muscleIdFrom, muscleOrderFrom, index)
{

    if(index == 0)
    {
        alert("Muscle is already at the top of the list");
        return;
    }

    table = $("#muslce_order_table");

    console.log(table == null ? "null" : "not null");

    row = table.rows(index);

    muscleIdTo = row.attr("data-id");
    muscleOrderTo = row.attr("data-order");

    console.log("muscleIdFrom " + muscleIdFrom + " muscleOrderFrom " + muscleOrderFrom);
    console.log("muscleIdTo " + muscleIdTo + " muscleOrderTo " + muscleOrderTo);

}

错误指向此行:

 row = table.rows(index);

在我的控制台中,日志“非空”,因此table元素未定义。

1 个答案:

答案 0 :(得分:5)

.rows不是jQuery方法。更改代码以检索行,如下所示

row = table.find('tr').eq(index);