Esc键在html中就像重置按钮一样 [英] Esc key acts like reset button in html

查看:207
本文介绍了Esc键在html中就像重置按钮一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个带有重置和提交按钮的文本框。重置按钮工作正常。但是当我在这两个文本框中输入某些内容并按Esc时,值就会消失。事件就像重置按钮一样。我不知道如何控制它。非常感谢您的帮助......感谢...

 < input type =textname =/> < input type =textname =/> 

< input type =buttonvalue =Search/> < input type =resetvalue =Reset/>


解决方案

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



<$ p $($)$ $ $ $($)$ $ $($)$ $ $
});

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

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

解决方案

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

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

add above script in your code to prevent default functionality

这篇关于Esc键在html中就像重置按钮一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆