这个片段中变量“element”的类型是什么? 我认为这是一个数字(一个ID或什么),但现在,我不知道。 代码有效,但我不明白,为什么var元素可以用于for循环,就像数组一样。有没有关于这个的解释?什么是document.getElementById()的返回类型
<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>
https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById – j08691
'document.getElementById( )'返回一个'HTMLElement'或'null' –
@MikaelLennholm:'元素',而不是'HTMLElement':https://www.w3.org/TR/dom/#nonelementparentnode –