-1

我的脚本有问题。我在 setTimout 中使用 jQuery.post 函数,它TypeError: g.nodeName is undefined在 Firebug 上返回。这是我的脚本:

jQuery(function($) {
var timer;

    $("#tabela-orcamento .item .item-qtd .qtd-item").keyup(function() {     
        clearTimeout(timer);

        timer = setTimeout(function() {         
            $.post("../../aj_orc.php?op=atualizaQtd", {
                item: $(this).parents(".item").attr("data-item"),
                qtd: $(this).val()
            }, function(data) {
                $("#retornos").html(data);
            });
        },1000);
    });
});

有什么问题吗?

4

1 回答 1

4

您遇到了问题,因为this您的超时内部指的是您可能认为的另一个上下文。只需引入另一个that作为中间变量:

jQuery(function($) {
    var timer;

    $("#tabela-orcamento .item .item-qtd .qtd-item").keyup(function() {     
        clearTimeout(timer);

        var $that = $(this);
        timer = setTimeout(function() {         
            $.post("../../aj_orc.php?op=atualizaQtd", {
                item: $that.parents(".item").attr("data-item"),
                qtd: $that.val()
            }, function(data) {
                $("#retornos").html(data);
            });
        },1000);
    });
});
于 2013-05-08T10:37:19.813 回答