<!DOCTYPE html><html><head><meta charset="utf-8"><title>task</title><style type="text/css"> p span{ width:30px; height:50px; background:red; }</style></head><body><button id="sort">点击</button><p id="aqi-display"><span>1</span><span>2</span><span>3</span><span>4</span><span>5</span></p><script type="text/javascript">var sort=document.getElementById('sort');var myarea=document.getElementById('aqi-display');sort.addEventListener('click',function(){// for(var i=0;i<=myarea.children.length;i++){// var j=[// myarea.children[i].offsetHeight// ];// } 我用下面的方式可以得到五个元素的高,形成数组,但是为什么用上面这种循环的方式就不行,一直说offsetHeight没有定义,求解释一下,谢谢var j=[myarea.children[0].offsetHeight,myarea.children[1].offsetHeight,myarea.children[2].offsetHeight,myarea.children[3].offsetHeight,myarea.children[4].offsetHeight];console.log(j);})</script></body></html>
添加回答
举报
0/150
提交
取消