“事件”是JavaScript中的保留字吗? [英] Is 'event' a reserved word in JavaScript?
问题描述
采取这个功能:
< script type =text / javascript>
函数showChar(sSomeData,oEvent)
{
alert(oEvent.keyCode);
返回true;
}
< / script>
当我这样调用这个函数:
< input type =textid =txtTextBoxonkeypress =return showChar('some text',oEvent); />
我收到一个JS错误:Microsoft JScript运行时错误:'oEvent'未定义
但是,如果我重命名oEvent与'事件'像:
<输入type =textid =txtTextBoxonkeypress =return showChar('some text',event); />
然后它工作正常。我的结论是事件是Java脚本中代表事件
参数的保留字。但是,当我检查网络时,我没有看到事件作为保留字。
我错了,还没有真正记录为保留字? p>
谢谢!
这不是一个保留关键字,至少IE中的全局变量。
I am a beginner to Javascript. And when I was practicing I have noticed something.
Take this function:
<script type="text/javascript">
function showChar(sSomeData, oEvent)
{
alert (oEvent.keyCode);
return true;
}
</script>
When I call this function as this:
<input type="text" id="txtTextBox" onkeypress="return showChar('some text', oEvent);" />
I get a JS error: "Microsoft JScript runtime error: 'oEvent' is undefined"
But if I rename oEvent with 'event' like:
<input type="text" id="txtTextBox" onkeypress="return showChar('some text', event);" />
Then it works fine. My conclusion is 'event'is a reserved word which stands for event argument in Java Script. But when I have checked the net I did not see 'event' as a reserved word.
Am I mistaken or it is not really documented as a reserved word?
Thanks!
It is not a reserved keyword, but it is a global variable in IE at least.
这篇关于“事件”是JavaScript中的保留字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!