所以我有这样的一个表:JavaScript的DOM:HTML表格操作问题
<table class="inventoryItems" id="inventoryItems">
<tr>
<th id="itemCost" class="noLeft">id </th>
<th id="soldAmount" class="right">Item Description </th>
</tr>
<tr id="itemRow">
<th >
<input onBlur="shapeMapper(this)" ></input>
</th>
<th >
<input onBlur="shapeMapper(this)" ></input>
</th>
</tr>
</table>
只是一个非常简单的表格
,我想通过以下形式的javscript操纵它:
function shapeMapper(arg){
//arg goes unused for now.
var tblName = "inventoryItems";
var tbl = document.getElementById(tblName);
var soldAmount = document.getElementById("soldAmount").cellIndex;
var itemCost = document.getElementById("itemCost").cellIndex;
var rowCount = tbl.rows.length;
var itemList = "";
var totalCost=0;
var totalSold=0;
for(var i = 1; i<=rowCount-1 ; i++){
var fC = tbl.rows[i].cells[itemCost].firstChild;
r=tbl.rows[i];
alert(r.cells[itemCost].value);
totalCost = totalCost + Number(r.cells[itemCost].firstChild.value) ;
totalSold = totalSold + Number(r.cells[soldAmount].firstChild.value) ;
}
}
但r.cells[itemCost].firstChild.value
即使输入框中键入的值回到“未定义”...有没有人有任何想法为什么?
其驱使我绝对坚果。
谢谢!
下次正确缩进。当问题本身无法阅读时,没有人会解决问题。 – Joseph 2012-04-28 05:15:42
可读性是相对的......不是判断的基准 – albert 2012-04-28 09:27:23