本文實例講述了JS實現向表格行添加新單元格的方法。分享給大家供大家參考。具體如下:
下面的JS代碼可以想表格中指定id的行插入新的單元格
<!DOCTYPE html><html><head><script>function insCell(){var x=document.getElementById('tr1').insertCell(0);x.innerHTML="The famous";}</script></head><body><table border="1"><tr id="tr1"><td>Peter</td><td>Griffin</td></tr></table><br><input type="button" onclick="insCell()" value="Insert cell"></body></html>
希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答