忘了以下代码,实现主窗口中表行动态增加
<input type="button" class="form1" value="增加商品" onClick="addLine()">

解决方案 »

  1.   

    弹出窗口的jsfunction  show(obj)       
    {    
       if(obj.rowIndex!=0)       
      {       
       //这里,因为你clone了一行,这行里面的pcode就变两个了所以得用索引来访问了.
       //=====pcode[1].value=============
        //window.opener.document.jhform.pcode.value=obj.childNodes[0].innerText; 
        window.opener.document.jhform.pcode[1].value=obj.childNodes[0].innerText;   /////B处 ==
         window.close();     
      }       
    }   
      

  2.   

    你的opener中再你clone以后就包含了两个<input   readonly   name="pcode"   type="text"   size="10"   class="wenbenkuang"> //////A处这样的文本框了,所以你的使用window.opener.document.jhform.pcode[1].value
    来访问
      

  3.   

    window.opener.document.jhform.pcode[0].value 
    为你的隐藏了的行中的name="pcode"的控件
     <thead   id="thead1">       
        <TR   style="display:none"   bgColor="#ffffff">       
              <td   width="15%"   height="22"   align="center"> 
              <input   readonly   name="pcode"   type="text"   size="10"   class="wenbenkuang"> //////A处 
              <input   name="Submit3"   type="button"   class="form1"   value="选择"     onClick="javascript:window.open( '/myjxc/listProductOnly ', ' ', 'width=550,height=330,left=0,top=0 ')"> </td> 
                <td   width="27%"   align="center"> </td> 
        <td   width="10%"   align="center"> </td> 
        <td   width="9%"   align="center"> </td> 
        <td   width="6%"   align="center"> </td>     
        <td   width="8%"   align="center"> <input   type="text"   name="dj"   size="8"   class="wenbenkuang"> </td> 
        <td   width="8%"   align="center"> <input   type="text"   name="sl"   size="8"   class="wenbenkuang"> </td> 
        <td   width="13%"   align="center"> <input   readonly   type="text"   name="je"   size="10"   class="wenbenkuang"> </td> 
        <td   align="center"> <img   src="../images/delete.gif"   width="20"   height="20"> </td> 
        </TR> 
        </thead> 
      

  4.   

    非常感谢showbo,现在可以实现在window.opener.document.jhform.pcode[1].value中显示从弹出窗口中带过来的值了,但如果我接着再点击增加新的表行,再点弹出窗口时,如何实现同样的功能。因为我这个模块是实现:在一个订单中灵活增加多个商品,可能只加一行,可能增加多行。
    麻烦再指导,谢谢!!
      

  5.   

    在第一个页面加一个全局变量来控制你加了多少行,然后在弹出页面引用opener.变量名来访问这个pcode就行了
    var nowLine=0;//默认为你隐藏的那行
    function   addLine(){       
    elm=thead1.lastChild.cloneNode(true)       
    elm.style.display="";       
    tbody1.insertBefore(elm);  
    nowLine++;//添加了一行     
    }     弹出窗口的js
    function  show(obj)       
    {    
       if(obj.rowIndex!=0)       
      {     //使用opener的nowLine变量来访问name="pcode"的子控件  
        window.opener.document.jhform.pcode[opener.nowLine].value=obj.childNodes[0].innerText;   /////B处 ==
         window.close();     
      }       
    }   
      

  6.   

    下面是通过调试的代码,你参考下
    1.htm
    <html>
    <head></head>
    <body>
    <form   name="jhform"   action=""   method="post"> 
    <table   width="90%"   border="0"   align="center"   cellpadding="0"   cellspacing="1"   bordercolor="#FFFFFF"   bgcolor="#86c2fe">   
        <thead   id="thead1">       
        <TR   style="display:none"   bgColor="#ffffff">       
              <td   width="15%"   height="22"   align="center"> 
              <input   readonly   name="pcode"   type="text"   size="10"   class="wenbenkuang"> //////A处 
              <input   name="Submit3"   type="button"   class="form1"   value="选择"     onClick="javascript:window.open('2.htm ', '', 'width=550,height=330,left=0,top=0')"> </td> 
                <td   width="27%"   align="center"> </td> 
        <td   width="10%"   align="center"> </td> 
        <td   width="9%"   align="center"> </td> 
        <td   width="6%"   align="center"> </td>     
        <td   width="8%"   align="center"> <input   type="text"   name="dj"   size="8"   class="wenbenkuang"> </td> 
        <td   width="8%"   align="center"> <input   type="text"   name="sl"   size="8"   class="wenbenkuang"> </td> 
        <td   width="13%"   align="center"> <input   readonly   type="text"   name="je"   size="10"   class="wenbenkuang"> </td> 
        <td   align="center"> <img   src="../images/delete.gif"   width="20"   height="20"> </td> 
        </TR> 
        </thead> 
        <tbody   id="tbody1">       
            <tr   bgcolor="#C4DDF6">   
                <td   width="15%"   height="22"   align="center"> 商品代码 </td>                             
                <td   width="27%"   align="center"   class="big"> 商品名称 </td> 
        <td   width="10%"   align="center"   class="big_b"> 类别 </td> 
        <td   width="9%"   align="center"   class="big"> 规格 </td> 
        <td   width="6%"   align="center"   class="big"> 单位 </td> 
        <td   width="8%"   align="center"   class="big"> 单价 </td> 
        <td   width="8%"   align="center"   class="big"> 数量 </td> 
        <td   width="13%"   align="center"   class="big"> 金额 </td> 
        <td   width="4%"   align="center"   class="big"> 操作 </td> 
        </tr> 
        </tbody> 
    </table> 
    </form> 
    <input   type="button"   class="form1"   value="增加商品"   onClick="addLine()"> 
    <SCRIPT       LANGUAGE="JavaScript">       
    var nowLine=0;//默认为你隐藏的那行
    function   addLine(){       
    elm=thead1.lastChild.cloneNode(true)       
    elm.style.display="";       
    tbody1.insertBefore(elm);  
    nowLine++;//添加了一行     

    </script>
    </body>
    </html>2.htm
    <html>
    <head></head>
    <body>
    <table   width="100%"   border="0"   align="center"   cellpadding="0"   cellspacing="1"   bordercolor="#FFFFFF"   bgcolor="#86c2fe">   
            <tr   bgcolor="#C4DDF6">   
                <td   width="9%"   height="20"   align="center"> 商品代码 </td>                             
                <td   width="16%"   align="center"   class="big"> 商品名称 </td> 
        <td   width="12%"   align="center"   class="big_b"> 商品类别 </td> 
        <td   width="8%"   align="center"   class="big"> 规格 </td> 
        <td   width="9%"   align="center"   class="big"> 单位 </td> 
        <td   width="16%"   align="center"   class="big"> 产地 </td> 
        <td   align="center"   class="big"> 生产厂商 </td> 
        </tr> 
    <tr   style="cursor:hand"   onmouseover="this.bgColor= '#f0f0f0 '"   onMouseOut="this.bgColor= '#ffffff '"   bgColor="#ffffff">   
                <td   width="9%"   height="26"   align="center"> aaa </td>                             
                <td   width="16%"   align="center"> bbb </td> 
        <td   width="12%"   align="center"> ccc </td> 
        <td   width="8%"   align="center"> ddd </td> 
        <td   width="9%"   align="center"> eee </td> 
        <td   width="16%"   align="center"> fff </td> 
        <td   width="20%"   align="center"> ggg </td> 
    </tr> 
    </c:forEach> 
    </table> 
    <style>       
        tr{t:expression(this.ondblclick=function(){show(this)})}       
    </style>   
    <script   language=javascript> 
    function     show(obj)       
        {       
                if(obj.rowIndex!=0)       
                {       
                     window.opener.document.jhform.pcode[opener.nowLine].value=obj.childNodes[0].innerText;   /////B处 ==
         window.close();      
                }       
        }   
    </script> </body>
    </html>
      

  7.   

    1.htm
    <html>
    <head></head>
    <body>
    <form   name="jhform"   action=""   method="post"> 
    <table   width="90%"   border="0"   align="center"   cellpadding="0"   cellspacing="1"   bordercolor="#FFFFFF"   bgcolor="#86c2fe">   
        <thead   id="thead1">       
        <TR   style="display:none"   bgColor="#ffffff">       
              <td   width="15%"   height="22"   align="center"> 
              <input   readonly   name="pcode"   type="text"   size="10"   class="wenbenkuang">
              <input   name="Submit3"   type="button"   class="form1"   value="选择" > 
    <input type="button" onclick="tbody1.removeChild(this.parentNode.parentNode);" value="删除"/></td> 
                <td   width="27%"   align="center"> </td> 
        <td   width="10%"   align="center"> </td> 
        <td   width="9%"   align="center"> </td> 
        <td   width="6%"   align="center"> </td>     
        <td   width="8%"   align="center"> <input   type="text"   name="dj"   size="8"   class="wenbenkuang"> </td> 
        <td   width="8%"   align="center"> <input   type="text"   name="sl"   size="8"   class="wenbenkuang"> </td> 
        <td   width="13%"   align="center"> <input   readonly   type="text"   name="je"   size="10"   class="wenbenkuang"> </td> 
        <td   align="center"> <img   src="../images/delete.gif"   width="20"   height="20"> </td> 
        </TR> 
        </thead> 
        <tbody   id="tbody1">       
            <tr   bgcolor="#C4DDF6">   
                <td   width="15%"   height="22"   align="center"> 商品代码 </td>                             
                <td   width="27%"   align="center"   class="big"> 商品名称 </td> 
        <td   width="10%"   align="center"   class="big_b"> 类别 </td> 
        <td   width="9%"   align="center"   class="big"> 规格 </td> 
        <td   width="6%"   align="center"   class="big"> 单位 </td> 
        <td   width="8%"   align="center"   class="big"> 单价 </td> 
        <td   width="8%"   align="center"   class="big"> 数量 </td> 
        <td   width="13%"   align="center"   class="big"> 金额 </td> 
        <td   width="4%"   align="center"   class="big"> 操作 </td> 
        </tr> 
        </tbody> 
    </table> 
    </form> 
    <input   type="button"   class="form1"   value="增加商品"   onClick="addLine()"> 
    <SCRIPT       LANGUAGE="JavaScript">       
    var Index=0;//生成唯一id的变量,从0开始
    function   addLine(){       
    elm=thead1.lastChild.cloneNode(true)  
    var es=elm.getElementsByTagName("input"); 
    var ID="";
    for(var i=0;i<es.length;i++)
    {
      if(es[i].name=="pcode")
      {
        ID="pcode"+Index;//生成唯一id 
        es[i].id=ID;
      }
      else if(es[i].name=="Submit3")
      {
         es[i].onclick=function()//把打开窗口选择数据的单击事件放到这里
         {  
           window.open('2.htm?'+ID, '', 'width=550,height=330,left=0,top=0');//把这个pcode的id加上
         }   
      }
    }  
    elm.style.display="";       
    tbody1.insertBefore(elm);  
    Index++;//id加1以便生存唯一id   

    </script>
    </body>
    </html>
    2.htm
    <html>
    <head></head>
    <body>
    <table   width="100%"   border="0"   align="center"   cellpadding="0"   cellspacing="1"   bordercolor="#FFFFFF"   bgcolor="#86c2fe">   
            <tr   bgcolor="#C4DDF6">   
                <td   width="9%"   height="20"   align="center"> 商品代码 </td>                             
                <td   width="16%"   align="center"   class="big"> 商品名称 </td> 
        <td   width="12%"   align="center"   class="big_b"> 商品类别 </td> 
        <td   width="8%"   align="center"   class="big"> 规格 </td> 
        <td   width="9%"   align="center"   class="big"> 单位 </td> 
        <td   width="16%"   align="center"   class="big"> 产地 </td> 
        <td   align="center"   class="big"> 生产厂商 </td> 
        </tr> 
    <tr   style="cursor:hand"   onmouseover="this.bgColor= '#f0f0f0 '"   onMouseOut="this.bgColor= '#ffffff '"   bgColor="#ffffff">   
                <td   width="9%"   height="26"   align="center"> aaa </td>                             
                <td   width="16%"   align="center"> bbb </td> 
        <td   width="12%"   align="center"> ccc </td> 
        <td   width="8%"   align="center"> ddd </td> 
        <td   width="9%"   align="center"> eee </td> 
        <td   width="16%"   align="center"> fff </td> 
        <td   width="20%"   align="center"> ggg </td> 
    </tr> 
    </c:forEach> 
    </table> 
    <style>       
        tr{t:expression(this.ondblclick=function(){show(this)})}       
    </style>   
    <script   language="javascript">function     show(obj)       
        {       
                var NowLineId=location.search.substring(1);//从查询字符串获取要操作的opener上的控件id
                if(obj.rowIndex!=0)       
                {  
                  opener.document.getElementById(NowLineId).value=obj.childNodes[0].innerText;
                  window.close();      
                }       
        }   
    </script> 
    </body>
    </html>