button对象的onclick属性是怎么来的

button.html文件
<!DOCTYPE html>
<html>
    <head>
        <title>DOM</title>
    </head>
    <body>
        <button id="button">this is a button</button>
    </body>
</html>
然后在开发者工具的控制台(console)中加入button对象的点击事件:
button.onclick = function(){
    alert("Hello World");
}
点击按钮时的效果:

https://img.mukewang.com/5bbb6e480001428707690134.jpg

为什么会有一个button对象呢?
  因为浏览器解析上面的HTML时,会把标记解析为对象,如将<button>元素解析为button对象,
  因此我们会有一个button对象

那button对象的onclick属性是怎么来的呢?
  在此网站(https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLButtonElement)中的
  的HTMLButtonElement,HTMLElement,
  Element和Node接口中均没有找到onclick属性


慕标琳琳
浏览 971回答 2
2回答

吃鸡游戏

属于&nbsp;Global attributeGlobal attributes

哔哔one

HTML中的&nbsp;<button>&nbsp;标签实现自DOM的&nbsp;HTMLButtonElement接口类&nbsp;,HTMLButtonElement又继承了一系列类,继承的基类是这个&nbsp;EventTarget&nbsp;。最后的这个EventTarget是拥有 “通过属性注册事件” 的能力的
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript