2020-09-29

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Document</title>

</head>

<style>

  *{

    margin: 0;

    padding: 0;

  }

  .box{

    width: 200px;

    height: 200px;

    background-color: plum;

    line-height: 200px;

    text-align: center;

    margin: 100px auto;

    color: #ffffff;

    cursor: pointer;

  }

  td{

    width: 200px;

    text-align: center;

    height: 30px;

  }

  th{

    background-color: palevioletred;

    width: 200px;

    height: 30px;

  }

  td,th{

    border: 1px solid #ffb0b0;

  }

  .btn{

    border: none;

    width: 40%;

    background-color: rgb(231, 57, 26);

    color: #ffffff;

    height: 25px;

    border-radius: 5px;

    cursor: pointer;

  }

  .table-box{

    margin: 20px auto;

    width: 810px;

  }

  table{

    border-collapse: collapse;/*关键代码*/

  }

</style>

<body>

   <div class="table-box">

      <table>

         <thead>

           <tr>

             <th>name</th>

             <th>sex</th>

             <th>age</th>

             <th>操作</th>

           </tr>

         </thead>

         <tbody id="conteiner"></tbody>

      </table>

   </div>

</body>

<script>

window.onload = function(){

  var list  = [ {name:"张飞",sex:"男",age:'20',btn:"删除"},

                {name:"刘备",sex:"男",age:'20',btn:"删除"},

                {name:"关羽",sex:"男",age:'20',btn:"删除"},

                {name:"马超",sex:"男",age:'20',btn:"删除"},

                {name:"赵云",sex:"男",age:'20',btn:"删除"},

                {name:"黄忠",sex:"男",age:'20',btn:"删除"}

              ]

  var tbodydom = document.getElementById('conteiner')

  function render(list){

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

     var trbox = document.createElement('tr')

     var chlid = list[i]

     for(var key in chlid ){

        var tdDom = document.createElement('td')

        tdDom.innerText = chlid[key]

        trbox.appendChild(tdDom)

        tbodydom.appendChild(trbox)

     }

   }

 }

 render(list)

}

</script>

</html>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容