如何恢复模糊值?

问题描述 投票:0回答: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
        });
    });
});
当我在模糊事件上调用它时,

变量

temp
变成空字符串。为什么会发生这种情况以及如何解决?

jquery autocomplete blur
1个回答
0
投票

发现了故障,虽然我无法完全解释自己......
我刚刚将

temp = inputField.val();
移至
if(inputField.val(undefined) != true){
上方,并且成功了。

© www.soinside.com 2019 - 2024. All rights reserved.