我有表,哪些應該改變表中的每個輸入的值的JavaScript代碼。我如何訪問內部單元格元素?如何更改表格單元格中輸入的JavaScript
這是我的html代碼:
<table border="1" id="myTable">
<tr>
<th><input type="text" size="2"></th>
<th><input type="text" size="2"></th>
<th><input type="text" size="2"></th>
<th><input type="text" size="2"></th>
<th><input type="text" size="2"></th>
<th><input type="text" size="2"></th>
</tr>
</table>
,這是我的javascript代碼:
function showSuccess(msg) {
Messenger({
extraClasses: 'messenger-fixed messenger-on-right messenger-on-top',
theme: 'flat'
}).post(msg);
}
function pushArray(){
var oTable = document.getElementById('myTable');
//gets rows of table
var rowLength = oTable.rows.length;
//loops through rows
for (i = 0; i < rowLength; i++) {
//gets cells of current row
var oCells = oTable.rows[i].cells;
//gets amount of cells of current row
var cellLength = oCells.length;
//loops through each cell in current row
for(var j = 0; j < cellLength; j++){
// here i should change the value of input
oCells[j].innerHTML="NEW CONTENT";
}
}
}
你不應該使用了TD,而不是個?你也試過用調試器試過這個嗎? – CamJohnson26