0

我有一个动态表,如下所示:http: //jsfiddle.net/yvonnezoe/q524G/2/。我想从表中的每一行中获取 2 个值。所以我创建了2个变量:

fbType = $('td.nth(2)', $(this)).html();
fbNum = $('td.nth(3)', $(this)).html();

然后为了显示它们,我尝试了:

$('#test').append(fbType + fbNum);

但什么都没有出现。我该怎么做?

4

1 回答 1

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 ");
        }
    });
}
于 2013-05-02T09:11:58.653 回答