我有以下 html 代码,它是一个包含一些关于用户教育的字段的表格。
<table border="0" style="margin: auto; ">
<td width="60%" >
<fieldset style="width:530px; padding-left:5px; background-color:white " >
<INPUT type="button" value="Add new Table" onclick="addRow('dataTable')" />
School/University/College*</br>
<input name="school_1" type="text" size="73"/>
</br></br>
Field of Study</br>
<input name="field_1" type="text" size="73"/>
</br></br>
Specialized subjects</br>
<input name="specialized_subject_1" type="text" size="73" />
</br></br>
Degree</br>
<input name="degree_1" type="text" size="73"/>
</br></br>
Grade</br>
<input name="grade_1" type="text" size="73" />
</br></br></br>
Attended from: <select name="month_1_1">
<option value=" "> EMPTY </option>
<option value="January">January</option>
</select>
<select id="year_1_1" name="year_1_1">
<option value=" "> EMPTY </option>
<option value="2009">2009</option>
</select>
Until: <select name="month_1_2">
<option value=" "> EMPTY </option>
<option value="January">January</option>
</select>
<select name="year_1_2">
<option value=" "> EMPTY </option>
<option value="2009">2009</option>
</select>
</h2></font>
</fieldset>
</td>
</table>
我正在使用以下 Javascript 代码,以便用户在此下添加一个新表,以添加有关他的教育的更多详细信息,以防他想这样做。我的 Javascript 代码不起作用。任何想法如何解决这一问题?
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
</SCRIPT>