JS實(shí)現(xiàn)控制表格行文本對(duì)齊的方法

字號(hào):


    這篇文章主要介紹了JS實(shí)現(xiàn)控制表格行文本對(duì)齊的方法,涉及javascript操作表格樣式的相關(guān)技巧,需要的朋友可以參考下
    本文實(shí)例講述了JS實(shí)現(xiàn)控制表格行文本對(duì)齊的方法。分享給大家供大家參考。具體如下:
    下面的JS代碼可以控制表格內(nèi)的整行文本向左或者向右對(duì)齊
    <!DOCTYPE html>
    <html>
    <head>
    <script>
    function leftAlign()
    {
    document.getElementById('header').align="left";
    }
    </script>
    </head>
    <body>
    <table>
    <tr id="header">
    <th>Firstname</th>
    <th>Lastname</th>
    </tr>
    <tr>
    <td>Peter</td>
    <td>Griffin</td>
    </tr>
    </table>
    <br>
    <input type="button" onclick="leftAlign()" value="Left-align table row"/>
    <p><b>Note:</b> This example does not work in Internet Explorer.</p>
    </body>
    </html>
    希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。