Autocomplete jquery自动完成如何恢复模糊值?
我试过这个:Autocomplete jquery自动完成如何恢复模糊值?,autocomplete,restore,blur,Autocomplete,Restore,Blur,我试过这个: $(function(){ $('.aComplete').each(function(){ var inputField = $(this); $(this).autocomplete({ source :"index.php?action=acomplete&name="+$(this).attr("name"), minLength:1 })
$(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
时,它变成了一个空字符串
为什么会发生这种情况?如何修复?发现了故障,尽管我无法完全解释自己…
我刚刚移动了
temp=inputField.val()上面的代码>如果(inputField.val(未定义)!=true){
成功了