Firefox中的文本框onKeyPress不起作用 [英] Textbox onKeyPress in Firefox not working

查看:96
本文介绍了Firefox中的文本框onKeyPress不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
<head>
    <script>   
        function handleKeyPress(evt) {   
            var nbr;   
            var nbr = (window.event) ? event.keyCode : evt.which;   
            alert(nbr);  
            return true; 
        }   
    </script> 
</head>
<body>
    <form>
        <input type=text name="txt" onkeypress="handleKeyPress();">
    </form>
</body>
</html>

这与IE完美兼容,但在Firefox中却无法正常工作.我正在使用IE8和Firefox 3

This is working perfectly with IE but not in Firefox. I'm using IE8 and Firefox 3

推荐答案

您错过了将event对象传递给handleKeyPress()调用.

You missed to pass event object to handleKeyPress() call.

<input type="text" name="txt" onkeypress="handleKeyPress(event);">

这篇关于Firefox中的文本框onKeyPress不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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