我想将 3 行追加到具有 3 列的表中。我尝试了以下代码,但它不起作用。
html代码:
<table width="50%" border="0" cellspacing="2" cellpadding="5" class="height">
</table>
javascript代码:
var table=document.getElementsByClassName('height') ;
//creating inputfield with attribute
var newField=document.createElement('input');
newField.setAttribute('type','text');
//creating <td>
var newTd=document.createElement('td');
//appending newField into td
newTd.appendChild(newField);
//creating <tr> element
var newTr=document.createElement('tr');
//appending 3 <td>(newTd) elements,but here 3 <td>'s are not appending
newTr.appendChild(newTd);
newTr.appendChild(newTd);
newTr.appendChild(newTd);
//the above code was not working,if it works I want to append 3 <tr> into <table>.
我不想使用外部库(jquery,....)。
谢谢