Trigger autocomplete without submitting a form

后端 未结 10 635
甜味超标
甜味超标 2020-11-29 01:44

I am writing a very simple web app with three text inputs. The inputs are used to generate a result, but all the work is done in Javascript, so there is no need to submit a

10条回答
  •  执念已碎
    2020-11-29 02:08

    You can use jQuery to persist autocomplete data in the localstorage when focusout and when focusin it autocompletes to the value persisted.

    i.e.

    $(function(){
     $('#txtElement').on('focusout',function(){
       $(this).data('fldName',$(this).val());
     }
    
     $('#txtElement').on('focusin',function(){
       $(this).val($(this).data('fldName'));
     }
    }
    

    You can also bind persistence logic on other events also depending on the your application requirement.

提交回复
热议问题