我试过这个:
$(function(){
$('.aComplete').each(function(){
var inputField = $(this);
$(this).autocomplete({
source :"index.php?action=acomplete&name="+$(this).attr("name"),
minLength:1
})
//clear the input on click
.focus(function(){
if(inputField.val(undefined) != true){
temp = inputField.val();
inputField.val(undefined);
}
inputField.data("autocomplete").search(inputField.val());
//restore initial value if nothing was typed
}).blur(function(){
//check if field is empty and restore value from `temp` if so
alert(temp); //this shows empty string
});
});
});
但是,有趣的是,当我在 blur 事件中调用它时,我的变量temp
变成了一个空字符串。
为什么会发生这种情况,如何解决?