DOM
当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model)。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>获取元素节点的方法</title>
<script>
window.onload=function () {
var id=document.getElementById("box");
document.write(id+"<br/>");
var name=document.getElementsByTagName("box1");
document.write(name+"<br/>");
var class1=document.getElementsByClassName("box2");
document.write(class1);
}
</script>
</head>
<body>
<div id="box">
MW
</div>
<div name="box1">
MW
</div>
<div class="box2">
MW
</div>
</body>
</html>
效果图