美文网首页
table设置样式

table设置样式

作者: 5df463a52098 | 来源:发表于2018-08-22 10:40 被阅读9次
    1.css设置样式
     td{
      border:solid #add9c0; 
      border-width:0px 1px 1px 0px;
    }
        table{
            border:solid #add9c0;
            border-width:1px 0px 0px 1px;
            border-collapse: collapse;        
    }
    
    2.动态设置样式
    let tables = document.getElementById('container').querySelectorAll('table')
                for (let i = 0; i < tables.length; i++) {
                    let table = tables[i]
                    // table.setAttribute('border', '1')
                    table.style.borderCollapse = 'collapse'
                    table.style.width = '100%'
                    table.style.textAlign = 'left'
                    table.style.border = 'solid #dddddd'
                    table.style.borderWidth = '1px 0px 0px 1px'
                    let rows = table.rows
                    for (let i = 0; i < rows.length; i++) {
                        for (let j = 0; j < rows[i].cells.length; j++) {    // 遍历该行的 td
                            let td = rows[i].cells[j]
                            td.style.border = 'solid #dddddd'
                            td.style.padding = '0 10px 0 10px'
                            td.style.borderWidth = '0px 1px 1px 0px'
                        }
                    }
                }
    
    image.png

    相关文章

      网友评论

          本文标题:table设置样式

          本文链接:https://www.haomeiwen.com/subject/bbyeiftx.html