【问题标题】:Prevent the click event while press the enter key when button in focus in Jquery在Jquery中当按钮处于焦点时按Enter键防止点击事件
【发布时间】:2016-06-02 04:14:39
【问题描述】:

请告诉我,我创建了一个表单并按 Tab 键聚焦按钮。如果我按下回车键而不是鼠标单击事件,则 jquery 事件会同时触发按键和单击事件。那么如何防止点击事件。

【问题讨论】:

  • 浏览器就是这样设计的,以考虑用户的可用性..

标签: javascript jquery


【解决方案1】:

请试试这个:

$("#ButtonID").keypress(function(e){
   if(e.keyCode === 13){
       e.preventDefault();
   }
});

【讨论】:

    猜你喜欢
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多