2

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" />
4

2 回答 2

3

它在所有浏览器中都可以正常工作http://jsfiddle.net/xgTxK/2/

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

在您的代码中添加上述脚本以防止默认功能

于 2012-04-23T05:34:29.590 回答
1

我不确定这是否在所有浏览器中都是一致的,但我注意到 esc 按钮通常会重置在文本输入中键入的文本,但仅在仍然集中在文本输入中时。或者换句话说,如果 onchange 事件尚未发生,esc 将重置文本。

我假设要防止这种情况发生,需要使用 JavaScript 来捕获输入中的关键事件并防止默认行为。

于 2012-04-20T13:00:26.690 回答