0
我嘗試這樣做:jquery自動完成如何恢復模糊值?
$(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
});
});
});
但是,在有趣的事情是我的變量temp
成爲當我把它在模糊事件一個空字符串。
爲什麼會發生這種情況,以及如何解決?