如何在动态表中获取值?

时间:2013-05-02 09:02:57

标签: jquery

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

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

然后显示它们,我试过了:

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

但是没有出现过。 我该怎么办?

1 个答案:

答案 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 ");
        }
    });
}