猿问

Javascript:表中的订单列表项

我正在使用表中的 javascript 处理任务。我正在尝试添加订单列表但卡在该代码中。当点击一个按钮时,一个表格显示我已经实现。但是它应该用数字显示的东西我还需要添加订单列表。请任何可以帮助我解决这些问题的人。从这里获取灵感 ,但我的代码不是工作codepen 。请有人指出我正确的方向。

输出:

提前致谢。


<html>

<head></head>

<body>

  <h3>JavaScript Programming</h3>

  <hr/>   

  <input type="button" onclick="f1()" value="Get Data"  />

  <br/>

  <br/>

  <table id="table1"  border="2"> 

  </table>

  

  <script>  

    function  f1() {

      var  ar = ["HTML5", "CSS3", "JavaScript", "Angular JS", "Node JS", "Express JS"];

            

      var  str  =  "";

      for(var i  in  ar)

      {

        str =  str  +   "<tr><td>" +  ar[i]  +  "  </td> </tr>";

      }

           

      var obj = document.getElementById("table1");

      obj.innerHTML  = str;

    } 

  </script>

</body>

</html>


弑天下
浏览 138回答 1
1回答

largeQ

您必须首先将 listOfList定义为数组&nbsp;const listOfList = []ar[i]的第二个更改元素listOfList.push("<li>" + ar[i] + "</li>");function f1() {&nbsp; &nbsp; const listOfList = [];&nbsp; &nbsp; const ar = ["HTML5", "CSS3", "JavaScript", "Angular JS", "Node JS", "Express JS"];&nbsp; &nbsp;&nbsp; &nbsp; let str = "";&nbsp; &nbsp; for (let i in ar) {&nbsp; &nbsp; &nbsp; &nbsp; str = str + "<tr><td>" + (+i+1)+ "."+ ar[i] + "&nbsp; </td> </tr>";&nbsp; &nbsp; &nbsp; &nbsp; listOfList.push("<li>" + ar[i] + "</li>");&nbsp; &nbsp; }&nbsp; &nbsp; const obj = document.getElementById("table1");&nbsp; &nbsp; obj.innerHTML = str;}<html><head></head><body>&nbsp; <h3>JavaScript Programming</h3>&nbsp; <hr/>&nbsp; &nbsp;&nbsp; <input type="button" onclick="f1()" value="Get Data"&nbsp; />&nbsp; <br/>&nbsp; <br/>&nbsp; <table id="table1"&nbsp; border="2"></table></body></html>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答