jQuery - 回车发送消息提交表单

访问量: 140

参考: https://stackoverflow.com/a/19744607/445908

特别简单. 直接: 

HTML:
  <input class="submit_on_enter" type="text" name="q" placeholder="Search...">

JS:
  $('.submit_on_enter').keydown(function(event) {
    // enter has keyCode = 13, change it if you want to use another button
    if (event.keyCode == 13) {
      this.form.submit();  // 或者其他操作 
      return false;
    }
  });

订阅/RSS Feed

Subscribe

分类/category