0
我有一些代码在一个按键运行的函数:键输入无法使用Chrome?
document.onkeypress=function(e)
{
var e=window.event || e
var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
if (unicode == 39)
{
Rotate();
}
}
function Rotate()
{
myDiv.setAttribute('style', '-moz-transform:rotate(' + rotationAmount + 'deg); -o-transform:rotate(' + rotationAmount + 'deg);-webkit-transform:rotate(' + rotationAmount + 'deg);-ms-transform:rotate(' + rotationAmount + 'deg)');
}
而且无论出于何种原因,按键输入工作在Firefox,而不是浏览器。当我在Chrome中按下某个键时,什么也没有发生。我知道Rotate()函数在Chrome中工作,因为如果我在不同条件下调用它,它将毫无问题地运行。
您的'evtobj'变量看起来很夸张。你可以参考你的'e'。 – alex 2012-04-10 23:02:17