我有以下代码:
function optionkey()
{
e = window.event;
if( e.altKey )
{
return "down";
}
else
{
return "up";
}
}
interval = setInterval(function(){
if( optionkey() == "down" ) {
clearInterval(interval);
alert( 5 );
}
}, 100);
基本上代码应该alert(5)
在用户按下选项键时运行,但是我得到了很多错误:Uncaught TypeError: Cannot read property 'altKey' of undefined
谁能告诉我为什么会这样以及如何解决它?
谢谢。