我有一个示例代码:
<table id="modem_list">
<tr class="input_1" name="modem">
<td>iPad 1<input type="hidden" value="1" class="output_1"></td>
</tr>
<tr class="input_2" name="modem">
<td>iPad 2<input type="hidden" value="2" class="output_2"></td>
</tr>
<tr class="input_1" name="modem">
<td>iPad 1<input type="hidden" value="1" class="output_1"></td>
</tr>
</table>
<input type="button" class="submit" onclick="update()" value="submit" />
和 javascript
function update() {
var table = document.getElementById("modem_list");
var rowCount = table.rows.length;
for(var i=0; i<rowCount-1; i++) {
for(var j=i+1; j<rowCount; j++) {
if(table.rows[i] == table.rows[j]) {
rowCount--;
for(var k=j; k<rowCount; k++) {
table.rows[k] = table.rows[k+1];
table.deleteRow(k);
k--;
}
}
}
}
}
如何修复结果是:
<table id="modem_list">
<tr class="input_1" name="modem">
<td>iPad 1<input type="hidden" value="1" class="output_1"></td>
</tr>
<tr class="input_2" name="modem">
<td>iPad 2<input type="hidden" value="2" class="output_2"></td>
</tr>
</table>