<table border="0" width="96%" align="center" cellpadding="1"
cellspacing="1">
<tr>
<td  width="5%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">物品編號</font>
</td>
<td  width="10%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">物品名稱及規格</font>
</td>
<td  width="3%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">單位</font>
</td>
<td  width="5%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">單價</font>
</td>
<td  width="10%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">申請數量</font>
</td>
<td  width="5%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">申請金額</font>
</td>
<td   width="10%"nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">核定數量</font>
</td>
<td  width="10%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">已申請數量</font>
</td>
<td width="5%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">使用機台型號</font>
</td>
<td  width="10%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">財產編號</font>
</td>
<td width="10%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">希望回廠日</font>
</td>
<td width="10%" nowrap="nowrap" class="tdTopBottomLine">
<font class="fontColor">備注</font>
</td>
</tr>
<c:forEach items="${list}" var="applyItem" varStatus="s">
<tr onclick="editCell(this)">
<td width="5%" nowrap="nowrap" align="center">
${applyItem.materialNo}
</td>
<td width="10%" nowrap="nowrap" align="center">
${applyItem.materialName}
</td>
<td width="3%" nowrap="nowrap" align="left">
${applyItem.materialUnit}
</td>
<td width="5%" nowrap="nowrap" align="center">
<span id="spanmaterialPrice${s.count}"><fmt:formatNumber
value="${applyItem.materialPrice}" maxFractionDigits="10"
minFractionDigits="2" /> </span>
</td>
<td width="10%" nowrap="nowrap"  align="right">
<fmt:formatNumber value="${applyItem.applyQuantity }"
maxFractionDigits="0" minFractionDigits="0" />
</td>
<td width="5%" nowrap="nowrap" align="center">
<fmt:formatNumber value="${applyItem.applyAmount}"
maxFractionDigits="10" minFractionDigits="2" />
</td>
<td width="10%" nowrap="nowrap" id="td_CheckQty" align="right">
<!-- <span><input name="vouchQty${s.count}" id="vouchQty${s.count}"
onblur="addQuantity();" /></> -->
</td>
<td width="10%" nowrap="nowrap" align="right">
<fmt:formatNumber value="${applyItem.appvouQuantity}"
maxFractionDigits="0" minFractionDigits="0" />
</td>
<td width="5%" nowrap="nowrap" align="center">
${applyItem.useMacspec}
</td>
<td width="10%" nowrap="nowrap" align="center">
${applyItem.propertyNo}
</td>
<td width="10%" nowrap="nowrap" align="left">
${applyItem.resDate}
</td>
<td width="10%" nowrap="nowrap" align="left">
${applyItem.appDesc}
</td>
</tr>
</c:forEach>
</table>
上面的是用c:each循环出来的,想点击行的某个列 将某个列改为<span><input name="vouchQty${s.count}" id="vouchQty${s.count}" onblur="addQuantity();" /></span>  我描述的不清楚 但想一定有好心人帮忙! 
//将文本变为输入框
function editCell(trObj)
{
for (i = 1; i < trObj.cells.length; i++) {
trObj.cells[4].onclick=function editCell()
{
trObj.cells[6].innerHTML = "<span><input type='text' maxlength='20' id='checkQty" +i+ "' value='"+trObj.cells[4].innerText+"' /></span>";
document.getElementById("checkQty" +i+ "").attachEvent("onblur", function(){editCellOnbur(this.value)});
}
}
}
//文本框失去焦点时,需要更新表格的内容
function editCellOnbur(checkQty){
alert("object:"+checkQty);
//document.getElementById("td_CheckQty").innerHTML=document.getElementById(checkQty).value;
}
/* 
这个是js 我想动态给input加事件  可是我传过去的值是alert("object:"+checkQty); 弹出一看是object:undefined
*/ 

解决方案 »

  1.   

    加个setTimeout 0试试 ,刚innerHTML的可能找不到setTimeout(function(){
    document.getElementById("checkQty" +i+ "").attachEvent("onblur", function(){editCellOnbur(this.value)});
    },0)
      

  2.   

    貌似还没有用… 它弹出来的还是alert("object:"+checkQty);
      

  3.   

    动态添加的事件 是监听不到的jquery 有个 .live()  方法可以监听到后来添加的事件  你去看看 
      

  4.   

    请提供完整的js代码,比如editCell怎么调用的,js放在什么地方 
      

  5.   

    如果没有其它的onblur事件,就直接
    document.getElementById("checkQty" +i+ "").onblur= function({
        editCellOnbur(this.value)
    };
      

  6.   

     調用是在tr的單擊事件中… 完整的js就這麼多!沒別的了…