how prevent submit on press enter in twitter bootstrap typeahead plugin

前端 未结 5 2165
谎友^
谎友^ 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:37

    You can target that specific input by adding an ID to it and simply removing the keydown event for enter like so:

    JS

    $(document).ready(function() {
      $('form input').keydown(function(event){
        if(event.keyCode == 13) {
          event.preventDefault();
          return false;
        }
      });
    });
    

提交回复
热议问题