Javascript 如何保持';这';使用新函数jquery

Javascript 如何保持';这';使用新函数jquery,javascript,jquery,Javascript,Jquery,如何在不使用event.target.id的情况下使“this”保持在新函数中 $(document).on('keyup','input[type=text],input[type=password]',function() { alert($(this).val()); clearTimeout(TIMER); TIMER = setTimeout(function() { alert($(this).val()); } }

如何在不使用event.target.id的情况下使“this”保持在新函数中

$(document).on('keyup','input[type=text],input[type=password]',function()
{       
    alert($(this).val());

    clearTimeout(TIMER); TIMER = setTimeout(function()
    { 
        alert($(this).val());
    }
}
试试这个

$(document).on('keyup','input[type=text],input[type=password]',function()
{
    var myElement=$(this)       
    alert(myElement.val());

    clearTimeout(TIMER); TIMER = setTimeout(function()
    { 
        alert(myElement.val());
    }
}

如果我正确理解这个问题,您只需要指定一个局部变量,它将保留其值

var $input = $(this);

六羟甲基三聚氰胺六甲醚。。。看起来您只是想将keyup事件绑定到输入,如果是这样,我将从文档中删除on函数,并将其放在您想要绑定到的元素上。