jQuery parent()方法取tr的index() 取不到,新手求解!
羽異 2017-08-22 09:16:22 在做删除一行的操作:
var $trIndex = $(elem).parent().parent().index(); //此方法取不到值
var trIndex = elem.parentNode.parentNode.rowIndex //这个方法就可以;求解
JS代码如下:
function delTr(elem){
/* var $trIndex = $(elem).parent().parent().index(); */
var trIndex = elem.parentNode.parentNode.rowIndex;
$("#fsoIsTbl tr").eq(trIndex).remove();
}
JSP代码如下:
<logic:notEmpty name="fsoInfoSourcesList">
<logic:iterate id="fsoIsList" name="fsoInfoSourcesList" indexId="fsoIsIndex" >
<tr style="text-align: center; height: 30px;">
<td><bean:write name="fsoIsList" property="fbNumber"/></td>
<td><bean:write name="fsoIsList" property="fbColor"/></td>
<td><bean:write name="fsoIsList" property="proNumber"/></td>
<td><bean:write name="fsoIsList" property="proColor"/></td>
<td><bean:write name="fsoIsList" property="fbConsumption"/></td>
<td><bean:write name="fsoIsList" property="proFbType"/></td>
<td><bean:write name="fsoIsList" property="fiQuantity"/></td>
<td><input type="number" style="width:50px;" onblur="proCountBlur('${fsoIsList.fbConsumption}',this);" /></td>
<td><input type="number" style="width:70px;" step="0.1" required /></td>
<td>
<bean:define id="fiLocationStr" name="fsoIsList" property="fiLocation" type="java.lang.String"/>
<% request.setAttribute("filArray", fiLocationStr.split(",")); %>
<logic:notEmpty name="filArray" scope="request">
<bean:size id="filArrayLength" name="filArray" />
<logic:greaterThan value="1" name="filArrayLength">
<html:select property="fsoLocation">
<html:option value="0">请选择</html:option>
<logic:iterate id="filArr" name="filArray" scope="request">
<html:option value="${filArr}">${filArr}</html:option>
</logic:iterate>
</html:select>
</logic:greaterThan>
<logic:lessEqual value="1" name="filArrayLength">
<bean:write name="fsoIsList" property="fiLocation"/>
</logic:lessEqual>
</logic:notEmpty>
</td>
<td><input type="button" onclick="delTr(this);" value="删除" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>