所以我有這樣的一個表: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