[英]JavaScript function call inside the html tag
As i understand when we invoke a method this
contains reference to object
which invoke this method. 据我了解,当我们调用一个方法时,
this
包含对调用该方法的object
引用。 But what is an "object" and a "method" in the following case: 但是在以下情况下,什么是“对象”和“方法”:
Consider html
code snippet 考虑
html
代码段
<div id="parent">
<input type="submit" id="submit" value="submit" onclick="doThis(this)"/>
</div>
where doThis()
is JS
function, such that 其中
doThis()
是JS
函数,例如
doThis(obj){
obj.style.background="#ff00ff"
}
I know, that this
will be contained reference to submit
button, but i dont understand why. 我知道,
this
将包含对submit
按钮的引用,但是我不明白为什么。
See the HTML 5 specification : 请参阅HTML 5规范 :
When an event handler content attribute is set
设置事件处理程序的内容属性时
...
...
create a function object (as defined in ECMAScript edition 5 section 13.2 Creating Function Objects)
创建功能对象(如ECMAScript版本5第13.2节“创建功能对象”中所定义)
...
...
Set the corresponding event handler to the aforementioned function
将相应的事件处理程序设置为上述功能
and 和
Process the Event object
E
as follows:如下处理事件对象
E
:...
...
Invoke callback with one argument, the value of which is the Event object
E
, with the callbackthis
value set toE
's currentTarget.调用回调函数有一个参数,它的值是Event对象
E
,与回调this
值设置为E
的currentTarget当前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.