猿问
下载APP

这怎么长度为0

var  a = document.getElementsByTagName('div');

console.log(a.length)


for (i = 0; i < a.length ; i++){

alert(a[i].innerHTML);

}



weixin_慕的地4584504
浏览 184回答 4
4回答

莲_蓶濏__

要么你页面没div标签 要么你这js在前面div标签在后面 😷

莲_蓶濏__

<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><script>window.onload = function() {var  a = document.getElementsByTagName('div');console.log(a.length);for (var i = 0; i < a.length; i++){alert(a[i].innerHTML);}};</script></head><body><div>html</div><div>css</div><div>js</div></body></html>

莲_蓶濏__

<div>html</div><div>css</div><div>js</div><script>var  a = document.getElementsByTagName('div');console.log(a.length);for (i = 0; i < a.length; i++){alert(a[i].innerHTML);}</script>

慕设计5377700

什么长度为0,a.length?
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答