1.普通的input

 <input type="text" onkeydown="keyup_submit(event);">
  
  <script>
 function keyup_submit(e){ 
   var evt = window.event || e; 
   if (evt.keyCode == 13){
      //回车事件
    }
  }
</script>

2.vue中使用的input

<input type="text"  placeholder="请输入关键字"  v-focus v-model ="searchName" />

界面中需要有一个聚焦 v-focus,在回车时才好执行keypress

created () {
    let that = this;
    document.onkeypress = function(e) {
      var keycode = document.all ? event.keyCode : e.which;
      if (keycode == 13) {
       that.search();   // 回车搜索事件
        return false;
      }
    };
  },
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐