在不同输入中按Enter键时按钮单击事件触发(无表格) [英] Button Click event fires when pressing Enter key in different input (no forms)

查看:129
本文介绍了在不同输入中按Enter键时按钮单击事件触发(无表格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在Amount输入中按Enter时,此逻辑正在触发,我不相信它(它不在Chrome中)。如何防止这种情况,如果不在IE中阻止它,请处理它,以便点击事件中的逻辑不会触发。

This logic is firing when pressing "Enter" in the "Amount" input, and I don't believe it should (it doesn't in Chrome). How can I prevent this, and if not prevent it in IE, handle it so that the logic in the click event does not fire.

<html>
 <body>
   <div id="page">
     <div id="financed_amount">
      <h1>Financed Amount:</h1>
      <input type="text" id="amount" value="" />
     </div>
     <h1>Finance Options</h1>
     <div>
      <a id="shareLink" rel="leanModal" name="email" href="#email"></a>
      <button id="btnShare" class="share">Share this report</button>
     </div>
    </div>
   </body>
</html>

脚本

$("#btnShare").click(function (e) {
    // This logic is firing when pressing "Enter" in the "Amount" input
});




  • Jquery:1.7.2

  • IE 9

  • (在Chrome中运行)

  • 推荐答案

    我遇到了同样的问题并通过将 type =button属性添加到< button> 元素,IE将按钮视为简单按钮而不是提交按钮(这是< button> 元素的默认行为)。

    I had the same problem and solved it by adding type="button" attribute to the <button> element, by which IE thinks the button as a simple button instead of a submit button (which is default behavior of a <button> element).

    这篇关于在不同输入中按Enter键时按钮单击事件触发(无表格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆