原生的js实现table
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>原生js做table练习(runoob.com)</title> <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script> </head> <body> <table id='mytable'> <tr> <th>姓名</th> <th>年龄</th> </tr> </table> </body> </html> <script> window.onload=function(){ var table1 = document.getElementById('mytable'); var arr = [ { name:"张三", age:12 }, { name:"李四", age:34 } ] var test = "" for(let i=0; i < arr.length; i++){ test += "<tr>" let obj = arr[i] console.log(obj) let keys = Object.keys(obj) for(let j =0; j<keys.length;j++){ test += "<td>"+ obj[keys[j]] + "</td>" } test += "</tr>" } table1.innerHTML += test } </script>
相关推荐
momode 2020-09-11
世樹 2020-11-11
SCNUHB 2020-11-10
bleach00 2020-11-10
FellowYourHeart 2020-10-05
思君夜未眠 2020-09-04
jessieHJ 2020-08-19
行吟阁 2020-08-09
表格的现在还是较为常用的一种标签,但不是用来布局,常见处理、显示表格式数据。在HTML网页中,要想创建表格,就需要使用表格相关的标签。<table> <tr> <td>单元格内的文字</td> ...
gufudhn 2020-08-09
末点 2020-08-03
nimeijian 2020-07-30
好记忆也需烂 2020-07-28
zlsdmx 2020-07-05
tomson 2020-07-05
tianqi 2020-07-05
onlykg 2020-07-04