javascript - Esc key acts like reset button in html - Stack Overflow

I am having two text boxes with a reset and a submit button. The reset button is working fine.But whe

I am having two text boxes with a reset and a submit button. The reset button is working fine. But when i enter something in those two text boxes and press esc, the values gets disappeared. Event acts like a reset button. I am not sure how to control it. Much appreciate your help... Thanks...

<input type="text" name="" /> <input type="text" name="" /> 

<input type="button" value="Search" /> <input type="reset" value="Reset" />

I am having two text boxes with a reset and a submit button. The reset button is working fine. But when i enter something in those two text boxes and press esc, the values gets disappeared. Event acts like a reset button. I am not sure how to control it. Much appreciate your help... Thanks...

<input type="text" name="" /> <input type="text" name="" /> 

<input type="button" value="Search" /> <input type="reset" value="Reset" />
Share Improve this question edited Apr 20, 2012 at 15:15 Yorgo 2,6781 gold badge17 silver badges25 bronze badges asked Apr 20, 2012 at 11:02 steevesteeve 6994 gold badges10 silver badges21 bronze badges 7
  • <input type="text" name="" /> <input type="text" name="" /> input type="button" value="Search" /> <input type="reset" value="Reset" /> – steeve Commented Apr 20, 2012 at 11:05
  • 1 You'll have to provide more code than that. – Goldie Commented Apr 20, 2012 at 11:19
  • 1 @Riyas see this once, I couldn't find any reset functionality when I press esc jsfiddle/xgTxK/1 – Valli69 Commented Apr 20, 2012 at 11:25
  • Any JavaScript included in your page? – German Latorre Commented Apr 20, 2012 at 12:48
  • @Riyas: when you provide code, write it in the question, not in ments – Alessandro Pezzato Commented Apr 20, 2012 at 13:02
 |  Show 2 more ments

2 Answers 2

Reset to default 3

It's working fine in all browsers http://jsfiddle/xgTxK/2/

$(document).keydown(function (e) {
    if(e.keyCode==27){
        e.preventDefault();
    }
});

add above script in your code to prevent default functionality

I'm not sure if this is consistent across all browsers, but I've noticed esc button will typically reset the text typed in a text input, but only while still focused within the text input. Or to put another way, esc will reset the text if the onchange event hasn't occured yet.

And I would assume to prevent this would need to use JavaScript to capture the key events within the input and prevent the default behavior.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745358161a4624237.html

相关推荐

  • javascript - Esc key acts like reset button in html - Stack Overflow

    I am having two text boxes with a reset and a submit button. The reset button is working fine.But whe

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信