【问题标题】:input change event on enter key not working in IEEnter 键上的输入更改事件在 IE 中不起作用
【发布时间】:2016-07-28 17:14:13
【问题描述】:

$("#inputBoxWidth").change(function() {
  var curValue = $("#inputBoxWidth").val();
  alert(curValue);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
  <input type="text" id="inputBoxWidth">
</form>

当我在所有浏览器中按回车键时,我会得到除 IE 之外的警报功能。在 IE 中,我必须在输入元素之外单击,这样输入才会失去焦点并且可以正常工作。当按下回车时,我需要 IE 的行为与其他浏览器相同,警报弹出窗口会显示当前值。如何做到这一点?

【问题讨论】:

  • 为什么不在form-submit事件上做呢?

标签: javascript jquery


【解决方案1】:

您可以做的是使用keyup 事件。

这给了你:

$("#inputBoxWidth").keyup(function() { // Your code });

不要使用keydown 事件,因为如果你想获取输入的值,它会在按键被按下之前给出值。

:)

【讨论】:

    【解决方案2】:

    https://developer.mozilla.org/en-US/docs/Web/Events/change

    根据 QuirksMode,Chrome 和 Firefox 已经兼容一段时间了,但 IE9 及更早版本的 IE10 支持不完全。

    您将不得不编写一些条件代码来显式检查浏览器是否为 IE 并编写解决方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      相关资源
      最近更新 更多