此代码段中变量“元素”的类型是什么?
我以为它是一个数字(一个 ID 或其他东西),但现在,我不知道。
代码有效,但我不明白,为什么 var 元素可以在 for 循环中使用,就像数组一样。对此有什么解释吗?
<script type="text/javascript">
function showAtrributes() {
var element = document.getElementById("videos");
var listAttributes = "";
for(var attribute in element) {
var valueOfAtrrib = element.getAttribute(attribute);
listAttributes = listAttributes + attribute + ": " + valueOfAttrib + "\n";
}
alert(listAttributes);
}
</script>
最佳答案
The getElementById() method returns the element that has the ID attribute with the specified value. [....] Returns null if no elements with the specified ID exists.
所以它返回一个 HTMLElement 对象
source
关于javascript - document.getElementById() 的返回类型是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44633621/