html:
<h1>找对象</h1> <div id="div1"> <p>p1</p> <p>p2</p> <p>p3</p> </div> <div class="div2"></div> <input type="text" name="username">
js:
①
console.log(document.getElementById("div1"));
输出:
<div id="div1"> <p>p1</p> <p>p2</p> <p>p3</p> </div>
类型是 [object HTMLDivElement]
②
console.log(document.getElementsByTagName("p"));
输出:
[p, p, p, item: function, namedItem: function] 0: p 1: p 2: p length: 3 __proto__: HTMLCollection
类型是 [object HTMLCollection]
时间: 2024-10-10 09:57:28