我有一个动态表格,如下所示:http://jsfiddle.net/yvonnezoe/q524G/2/。 我想从表中的每一行获得2个值。所以我创建了两个变量:
fbType = $('td.nth(2)', $(this)).html();
fbNum = $('td.nth(3)', $(this)).html();
然后显示它们,我试过了:
$('#test').append(fbType + fbNum);
但是没有出现过。 我该怎么办?
答案 0 :(得分:1)
this
内的monitor
未指向tr
,因此请将tr
作为参数传递,然后尝试
$('#monitor').click(function () {
$('#status_table tr').each(function () {
$check = $('input:checkbox', this)
if ($check.is(':checked')) {
monitoring(this);
}
});
});
function monitoring(el) {
$('#test').append("checked");
fbType = $('td:nth-child(1)', el).html();
fbNum = $('td:nth-child(2)', el).html();
$('#test').append(fbType + fbNum);
$.post('/request', {
inputText: fbNum,
key_pressed: fbType.toString()
}).done(function (reply) {
if (reply == "on") {
$('#test').append("on ");
} else {
$('#test').append("off ");
}
});
}