我想使用行索引访问表格中的行。
当我尝试获取行时索引我得到:
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
元素未定义。
答案 0 :(得分:5)
.rows
不是jQuery方法。更改代码以检索行,如下所示
row = table.find('tr').eq(index);