开发者

How Can I Prevent the Enter keypress from Triggering a Button Click?

I have the following code snippet.

  $("#days").key开发者_StackOverflowpress(function(e){
      if(e.keyCode == 13){
         self.validateNightModalForm();
      }
  });

basically, it checks for enter then invoke a function.

My only problem is that IE8 also clicks a button. When I hit enter. I've checked it with all other browsers, but only IE8 does this.

Is there any way to prevent it?


Try adding those two lines:

if (e.keyCode == 13) {
    self.validateNightModalForm();
    e.preventDefault()
    return false;
}

Hopefully this will stop the keypress event from "going up" and trigger the form submit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜