onKeyPress事件Mozilla [英] onKeyPress event Mozilla

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

问题描述

如何在Firefox中使用onKeyPress事件处理程序? onKeyPress

似乎在Firefox中无法触发。

How can I use the onKeyPress event handler in Firefox? onKeyPress
doesn''t seem to fire in Firefox.

推荐答案

嗨Andy,
如何在Firefox中使用onKeyPress事件处理程序? onKeyPress
似乎没有在Firefox中启动。
How can I use the onKeyPress event handler in Firefox? onKeyPress
doesn''t seem to fire in Firefox.




确实如此!这在Firefox上工作正常。


< input type =" text"命名= QUOT;搜索和QUOT; onkeypress事件= QUOT;警报(嗨!);" />

< input type =" text"命名= QUOT;搜索和QUOT; onkeypress事件= QUOT;警报(嗨!);" />


也许您可以发布一些代码来向我们展示您正在尝试的内容

要做什么?


Rob


:)



It does! This works fine on Firefox.

<input type="text" name="search" onkeypress="alert(''Hi!'');" />
<input type="text" name="search" onKeyPress="alert(''Hi!'');" />

Perhaps you could post some code to show us exactly what you are trying
to do?

Rob

:)


以下似乎适用于IE但不适用于firefox ... (我将

事件从onKeyPress更改为onKeyDown

HTML


< input name =" strWnum" ; type =" text" value =" W" size =" 9"

onBlur =" checkInput();" onKeyDown =" checkEnter(event);">

..

..

..

< script language =" javascript" type =" ; text / javascript">

document.frmCheckOut.strWnum.onkeydown = checkEnter;

< / script>

.... .....

然后在我链接的.js文件中我有.....


功能checkEnter(e){

if(!e)var e = window.event;


if(e.keyCode)code = e.keyCode;

else if( e.which) code = e.which;

//代码包含所有浏览器中的按键


// alert(" A)代码是:" +代码)


if(code == 13){

if(e.keyCode)e.keyCode = 9;

另外e.which = 9;


}


}

//////// ////////////////////////////////////////////////// //////////////////////////////////////////////

函数checkInput(){

var strValue = document.frmCheckOut.strWnum.value;


if(String(strValue).length == 26 || String(strValue)。length == 16){

document.frmCheckOut.strWnum.value = String(strValue).substring(1,

10)


}否则if(String(strValue)。length == 13){

document.frmCheckOut.strWnum.value =" W" +

String(strValue).substring(2,10)

}


}


--------------------------------------------


我想在输入后将焦点切换到下一个表单元素。

就像我说的,它适用于IE而不是Firefox。


谢谢

Andy

The following seems to work in IE but not in firefox... (I changed the
event from onKeyPress to onKeyDown

HTML

<input name="strWnum" type="text" value="W" size="9"
onBlur="checkInput();" onKeyDown="checkEnter(event);">
..
..
..
<script language="javascript" type="text/javascript">
document.frmCheckOut.strWnum.onkeydown = checkEnter;
</script>
.........
then in my linked .js file I have.....

function checkEnter(e) {
if(!e) var e = window.event;

if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
//code contains the pressed key in all browsers

//alert("A) code is: " + code)

if(code==13) {
if (e.keyCode) e.keyCode = 9;
else e.which = 9;

}

}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkInput() {
var strValue = document.frmCheckOut.strWnum.value;

if (String(strValue).length == 26 || String(strValue).length == 16) {
document.frmCheckOut.strWnum.value = String(strValue).substring(1,
10)

} else if (String(strValue).length == 13) {
document.frmCheckOut.strWnum.value = "W" +
String(strValue).substring(2, 10)
}

}

--------------------------------------------

I want to switch the focus to the next form element once I hit enter.
Like i said, it works in IE and not in Firefox.

Thanks
Andy





LilAndy23写道:



LilAndy23 wrote:

if(code == 13){
if(e.keyCode)e.keyCode = 9;
e。 = 9;
if(code==13) {
if (e.keyCode) e.keyCode = 9;
else e.which = 9;




好​​好检查一下JavaScript控制台是否有什么办法无法找到

问题出在哪里,试图设置e.keyCode可能在Mozilla中给出了一个

脚本错误,不允许设置该属性。


不允许更改密钥的代码在Mozilla和大多数其他浏览器中的事件,以便该方法适用于IE / Win,但对于其他浏览器

你需要有所不同方法。你可以寻找下一个控件,并且

调用它的焦点方法。

-


Martin Honnen
< a rel =nofollowhref =http://JavaScript.FAQTs.com/target =_ blank> http://JavaScript.FAQTs.com/


这篇关于onKeyPress事件Mozilla的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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