在“金额”输入中按下“Enter”时会触发此逻辑,我认为它不应该(Chrome 中不存在)。我怎样才能阻止这种情况,如果不能在 IE 中阻止它,请处理它以使点击事件中的逻辑不会触发。
<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>
元素的默认行为)。
关于jquery - 在不同的输入中按下 Enter 键时触发 Button Click 事件(无表单),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12325066/