问题: 为什么我删除的时候总是从最后一行开始删除呢,不按我传进去的参数删除??????
页面代码:
<table>
<table id="dyntb" height=25 width="100%" border="0" align="center"
cellspacing="1" cellpadding="1">
<tbody>
  动态在这里添加行[代码:var tr1 = dyntb.insertRow();
tr1.id = "tr"; tr1.insertCell().innerHTML = '<td ><input type=button id=del_button name=del_line size=2 value=Ⅹ onClick=dynDelRow(this)></td>';  
tr1.insertCell().innerHTML = '<td><div align=left><input type=text name=res_name_arr size=15 value='+res_name+' v_name="手机型号" readonly=true></div></td>';
tr1.insertCell().innerHTML = '<td><div align=left><input type=text name=fit_name_arr size=15 value='+fit_name+' v_name="配件名称" readonly=true></div></td>';
tr1.insertCell().innerHTML = '<td><div align=left><input type=text name=fit_code_arr size=15 value='+fit_code+' v_name="配件代码" readonly=true></div></td>';
tr1.insertCell().innerHTML = '<td><div align=left><input type=text name=in_num_arr size=15 
  }]
</tbody>
函数:
function dynDelRow(id) 
{
    
     var args=dynDelRow.arguments[0];
     var objTD =args.parentElement;
     var objTR =objTD.parentElement;
     var currRowIndex = objTR.rowIndex;
   alert(currRowIndex);     var bb=parseInt(f9750Form.lines.value);
   // alert('bb=='+bb); 
     if(bb<=1) 
     {
location="<%=request.getContextPath()%>/f9750.do?operate=add_init";    
                return false;
       
     } else 
     {
       document.getElementById("dyntb").deleteRow(currRowIndex);---传的是行号
       document.f9750Form.lines.value = bb-1;
    }
   }

解决方案 »

  1.   

    http://topic.csdn.net/u/20081120/22/1a673e8a-b7e7-4a8a-b9ad-786a5df732c1.html
      

  2.   

    currRowIndex东西有值呢,而且和添加的行号是对应的
      

  3.   

    debug一下,里面什么东西都清楚了
      

  4.   

    <!-- main.jsp -->
    <%@ page contentType="text/html;charset=GB2312"%>
    <%@ include file="/public/include/top.jsp" %>
    <html:form action="/f9750">
    <input type="hidden" name="lines" value="0">
    <div id="Operation_Table">
    <table>
    <tr>
    <td align="center">
    <b>配件采购申请</b>
    </td>
    </tr>
    </table>
    <table align="center">
    <tr>
    <td width="12%">
    操作网点
    </td>
    <td align="left">
    <html:hidden property="in_group" styleId="in_group" value="<%=_groupId%>" />
    <%=_groupName%>
    </td>
    </tr>

    <tr>
    <td>
    手机品牌:
    </td>
    <td>
    <html:select property="brand_code" styleId="brand_code" onchange="change_resCode()">
    <option value="">
    --请选择--
    </option>
    <html:optionsCollection name="brand_name" />
    </html:select>
    </td>
    <td>
    手机型号:
    </td>
    <td>
    <html:select property="res_code" styleId="res_code">
    <option value="">
    --请选择--
    </option>
    </html:select>
    </td>
    </tr>
    <tr>
    <td>
    配件名称:
    </td>
    <td>
          <html:select property="fit_name" styleId="fit_name">
    <option value="">
    --请选择--
    </option>
    <html:optionsCollection name="fit_name" />
        </html:select>
    </td>
    <td>
    采购数量
    </td>
    <td >
    <input type="text" id="in_num" name="in_num" size="18" onblur="check()">
    </td>
    </tr>

    <tr>
    <td>
    备注:
    </td>
    <td>
    <textarea rows="3" cols="35" name="note" id="note"></textarea>
    </td>
    </tr>
    </table>
    <table>
    <tr>
    <td align="center">
    <input type="button" value="添加"
    onclick="dynAddRow(document.all.res_code,document.all.fit_name,document.all.in_num.value)">
    </td>
    </tr>
    </table>
    <table id="dyntb" height=25 width="100%" border="0" align="center"
    cellspacing="1" cellpadding="1">
    <tbody>
    <tr  bgcolor="9A9798" width="100%">
    <td  aligin="right"><b>采购清单:</b></td>
    </tr>
    <tr bgcolor="9A9798">
    <td height="25" nowrap>
    <div align="center"></div>
    </td>
    <td height="25" nowrap width="150">
    <div align="center">
    手机型号
    </div>
    </td>
    <td height="25" nowrap width="150">
    <div align="center">
    配件名称
    </div>
    </td>
    <td height="25" nowrap width="150">
    <div align="center">
    配件代码
    </div>
    </td>
    <td height="25" nowrap width="50">
    <div align="center">
    采购数量
    </div>
    </td> </tr>
    </tbody>
    </table>
    <table>
    <tr>
    <td align="center">
    <input type="button" id="subBtn" value="提交" onclick="do_add()">
    <input type="button"  value="返回" onclick="back()">
    <input type="button" value="清空" onclick="reset()">
    <input type="button" value="关闭" onclick="close1()">
    </td>
    </tr>
    </table>
    </div>
    </html:form><%@ include file="/public/include/bottom.jsp"%><script language="javascript">
    <%
    String msg=(String)request.getAttribute("msg")==null?"":(String)request.getAttribute("msg");
    if(!"".equals(msg)){
    %>
    rdShowMessageDialog('<%=msg%>');
    <%
    }
    %>core.loadUnit("rpccore");
    onload=function(){ core.rpc.onreceive = doProcess;
     
    }function check(){
     if(!isDecimal(document.all.in_num.value))
    {   
         document.all.in_num.value="";
         document.all.in_num.focus();
     rdShowMessageDialog("配件数量请输入数字",rdModeError);

    return;
    }
    }
    //批量添加
    function dynAddRow(code,obj,in_num){  
      var fit_name=obj[obj.selectedIndex].text;
      
     // obj[obj.selectedIndex].text
      var fit_code=document.getElementById("fit_name").value;
      var res_code=document.getElementById("res_code").value;
      var res_name=code[code.selectedIndex].text;
     //alert(res_name);
      if(res_code==""){
     
         rdShowMessageDialog("手机品牌和手机型号不能为空!",rdModeError);
         return;
        }
          if(document.getElementById("fit_name").value==""){
      
       rdShowMessageDialog("配件名称不能为空!");
       return ;
      }
       if(document.all.in_num.value=="")
    {   
         
            document.all.in_num.focus();
    rdShowMessageDialog("请输入采购数量",rdModeError);
    return;
    }
      if(document.all.in_num.value<=0){
      
        rdShowMessageDialog("数量不能为0");
        return 
       
        }
       f9750Form.lines.value = parseInt(f9750Form.lines.value)+1;
       //var tableobj = document.getElementById("dyntb");
       var tr1 = dyntb.insertRow();
    tr1.id = "tr"; tr1.insertCell().innerHTML = '<td nowrap><input type=button id=del_button name=del_line size=2 value=Ⅹ onClick=dynDelRow(this)></td>';  
    tr1.insertCell().innerHTML = '<td><div align=left><input type=text name=res_name_arr size=15 value='+res_name+' v_name="手机型号" readonly=true></div></td>';
    tr1.insertCell().innerHTML = '<td><div align=left><input type=text name=fit_name_arr size=15 value='+fit_name+' v_name="配件名称" readonly=true></div></td>';
    tr1.insertCell().innerHTML = '<td><div align=left><input type=text name=fit_code_arr size=15 value='+fit_code+' v_name="配件代码" readonly=true></div></td>';
    tr1.insertCell().innerHTML = '<td><div align=left><input type=text name=in_num_arr size=15 value='+in_num+' v_name="采购数量" readonly=true></div></td>';
    tr1.insertCell().innerHTML = '<td><div align=left><input type=hidden name=res_code_arr size=15 value='+res_code+' v_name="型号编码" readonly=true></div></td>';
      }
    //this.parentElement.rowIndex
    function dynDelRow(id) 
    {
        
         var args=dynDelRow.arguments[0];
         var objTD =args.parentElement;
         var objTR =objTD.parentElement;
         var currRowIndex = objTR.rowIndex;
        // alert(currRowIndex);     var bb=parseInt(f9750Form.lines.value);
       // alert('bb=='+bb); 
         if(bb<=1) 
         {
    location="<%=request.getContextPath()%>/f9750.do?operate=add_init";    
                    return false;
           
         } else 
         {
           dyntb.deleteRow(currRowIndex);
           document.f9750Form.lines.value = bb-1;
        }
      
      
    }
    function change_resCode()
    {   
    if (document.all.brand_code.value==""){
          clearoption(document.forms[0].res_code);
     return;
       }
       
       var myPacket = new RPCPacket("<%=select_rpc_jsp%>","");
       myPacket.data.add("key" ,"select_f9745_res");
       myPacket.data.add("type","select_res");   myPacket.data.add("brand_code",document.forms[0].brand_code.value);
     
       core.rpc.sendPacket(myPacket); 
    }
    function doProcess(packet)

       var type = packet.data.findValueByName("type");
       
       if(type=="select_res")
        {      var value =  packet.data.findValueByName("value") ;
        var text  =  packet.data.findValueByName("text") ;
        
        clearoption(document.all.res_code);
        if(value.length<1){
         rdShowMessageDialog('没有符合条件的对应型号');
         clearoption(document.all.res_code);
            return;
         }
        fillDropDown(document.all.res_code,value,text);
       } 
    }
    function fillDropDown(obj,_value,_text){
        obj.options.length = 0;
        var option1 = new Option('--请选择--','');
        obj.add(option1);
        for(var i=0; i<_value.length;i++)
        {
          var option = new Option(_text[i],_value[i]);
          obj.add(option);
      
       }
    }
    function clearoption(obj){
     
        obj.options.length = 0;
        var option1 = new Option('--请选择--','');
        obj.add(option1);
    }
    function do_add(){
       
       if(document.all.lines.value<=0){
       
          rdShowMessageDialog("请输入信息后再提交!",rdModeError);
    //document.all.cust_name.focus;
    return;
       
       
       }
         
            document.forms[0].action="<%=request.getContextPath()%>/f9750.do?operate=add";
            document.all.subBtn.disabled=true;
        document.forms[0].submit();
        
            
    }
       
       
     function back(){
     
            document.forms[0].action="<%=request.getContextPath()%>/f9750.do?operate=main";
           
        document.forms[0].submit();
       
       }
      
    function reset(){
     document.forms[0].reset();
    }function close1(){
    window.close();}</script>
      

  5.   

    deleteRow(currRowIndex);---传的是行号 currRowIndex推荐使用dom节点获得。