Trigger autocomplete without submitting a form

后端 未结 10 632
甜味超标
甜味超标 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:06

    ---WITHOUT IFRAME---

    Instead of using iframe, you can use action="javascript:void(0)", this way it doesn't go to another page and autocomplete will store the values.

    <form action="javascript:void(0)">
        <input type="text" name="firstName" />
        <button type="submit">Submit</button>
    </form>
    
    0 讨论(0)
  • 2020-11-29 02:07

    you can use "." in both iframe src and form action.

     <iframe id="remember" name="remember" style="display:none;" src="."></iframe>
     <form target="remember" method="post" action=".">
        <input type="text" id="path" size='110'>
        <button type="submit" onclick="doyouthing();">your button</button>
    </form>
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-29 02:14

    Maybe you can use this Twitter Typeahead...is a very complete implementation of a autocomplete, with local and remote prefetch, and this make use of localStorage to persist results and also it show a hint in the input element...the code is easy to understand and if you don't want to use the complete jquery plugin, I think you can take a look of the code to see how to achieve what you want...

    0 讨论(0)
提交回复
热议问题