how prevent submit on press enter in twitter bootstrap typeahead plugin

前端 未结 5 2171
谎友^
谎友^ 2021-02-07 12:36

I have a input text and I apply it typeahead plugin for suggesting items, but when I press enter key on input text it submit form.

How can I prevent form submit using tw

5条回答
  •  一生所求
    2021-02-07 13:29

    The first answer didn't worked for me, maybe because of updating the typeahead plugin, but I did passed the problem by using the 'alternative' input created by typehead:

    $(".twitter-typeahead > input").focus(function(){
        //disable btn when focusing the input
        $("#my_submit_button").prop('disabled', true);
    }).blur(function(){
        //enable btn when bluring the input
        $("#my_submit_button").prop('disabled', false);
    });
    

提交回复
热议问题