for循环的代码谁看看哪里错了

来源:9-5 getAttribute()方法

幻灭丶

2016-06-13 11:18

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style>
        li { height:30px; border-bottom:1px solid #333; }

    </style>
    <script>
        window.onload = function () {
            var a = document.getElementById("list");
            var b = ElementsByTagName("li");
            var arr = ["今天", "明天", "后天"]
            for (i = 0; i < arr.length;i++)
            { b[i].innerHTml = arr[i]; b[i].onclick = function () { } }
            

        }
    </script>
</head>
<body>
 <ul id="list">
   <li></li>
     <li></li>
     <li></li>
 </ul>
</body>
</html>


写回答 关注

2回答

  • 强中蝼蚁
    2016-06-13 11:31:06
    已采纳

    var b = document.getElementsByTagName("li");

    幻灭丶

    非常感谢!

    2016-06-19 23:13:55

    共 1 条回复 >

  • 慕村1994845
    2016-11-23 21:29:34
     b[i].innerHTml = arr[i]; b[i].onclick = function () { } 
     //这里.innerHTML中ML是不是写成小写呢?JS区分大小写的!


JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468869 学习 · 22582 问题

查看课程

相似问题