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");
}點擊按鈕時的效果:為什么會有一個button對象呢?
因為瀏覽器解析上面的HTML時,會把標記解析為對象,如將<button>元素解析為button對象,
因此我們會有一個button對象
那button對象的onclick屬性是怎么來的呢?
在此網站(https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLButtonElement)中的
的HTMLButtonElement,HTMLElement,
Element和Node接口中均沒有找到onclick屬性
button對象的onclick屬性是怎么來的
慕標琳琳
2018-10-03 19:15:45