简体   繁体   English

html标记内的JavaScript函数调用

[英]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 callback this value set to E 's currentTarget. 调用回调函数有一个参数,它的值是Event对象E ,与回调this值设置为E的currentTarget当前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM