所以我有一张这样的桌子:
<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
即使输入框中输入的值返回为“未定义”......有人知道为什么吗?
它把我逼疯了。
谢谢!