我的函数可能使用过时的 jquery 元素。例如,当我使用 close 和回调时:
$("input").each(function () {
var input = $(this);
//here for example we remove input from DOM
//and insert the new one input
$.ajax(url, function(){
fun(input)
}
});
function fun(input){
//do something
input.val('newValue')
}
问题是:我如何确定对变量的引用仍然正确。如果元素已被重新创建,我如何获得新输入的新参考(输入没有 id 和类)?
UPDATE1:我做了小更新。我们在函数fun中使用旧的输入引用。并且newValue将不适用于新输入,因为当前输入是旧值。