点击"输入"按钮不会在IE8中提交表单

Jef*_*eff 3 forms jquery internet-explorer-8

在我们的组织中,我们仍然使用IE8标准.在我们的一个基于网络的应用程序中,我们注意到我们无法通过Enter密钥提交表单.搜索网页后,我偶然发现了这个答案:https://stackoverflow.com/a/4629047/731052

虽然jQuery解决方案确实有效,但只要按下Enter键,我们的用户仍然可以获得"ding" .有没有办法防止这种情况发生?当我在像谷歌这样的网站上时,当我按下回车键时,我没有得到任何"叮当声".谢谢!

Sco*_*lby 11

用这个

if (e.which == '13') {
    e.preventDefault();
   //then put your code
   }
Run Code Online (Sandbox Code Playgroud)

假设您使用的是您有链接的问题中的代码

jQuery.fn.handle_enter_keypress = function() {
  if ($.browser.msie){
    $(this).find('input').keypress(function(e){
      // If the key pressed was enter
      if (e.which == '13') {
        $(this).closest('form')
        .find('button[type=submit],input[type=submit]')
        .filter(':first').click();
      }
    });
  }
}
Run Code Online (Sandbox Code Playgroud)