源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> <script> function alignCell(){ document.getElementById('td1').align="right"; document.getElementById('td2').align="right"; } </script> </head> <body> <table border="1"> <tr> <th>第一個名稱</th> <th>下一個名稱</th> </tr> <tr> <td id="td1">Peter</td> <td id="td2">Griffin</td> </tr> </table> <br> <input type="button" onclick="alignCell()" value="右對齊單元格" /> </body> </html>
運行結果