源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>开源教程(ossoft.cn)</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>
运行结果