-- main.htm ---------------------------
function openSub(i) {
  reval = window.open('sub.htm','ff','height=500px,width=860px,resizable=yes');  
}
<input type="text" id="code1"><a href=# onclick="openSub('1')">find</a>
<input type="text" id="code2"><a href=# onclick="openSub('2')">find</a>-- sub.htm ---------------------------
function doSelect(val){
 如何传递给父窗口相应的text?
 window.close();
}

解决方案 »

  1.   

    main.htm<html>
    <script>
    function openSub(i) {
      reval = window.open('sub.htm?param='+i,'ff','height=500px,width=860px,resizable=yes'); 

    </script>
    <input type="text" id="code1"> <a href=# onclick="openSub('1')">find </a>
    <input type="text" id="code2"> <a href=# onclick="openSub('2')">find </a> 
    </html>sub.htm<script>
    function doSelect(val){
    opener.document.getElementById(val).value='value';
    window.close();
    }
     //接收网址参数
            function GetUrlParameter(paramName)
            {
                var returnVal="";
                try{
                    var paramUrl=window.location.search;
                    //处理长度
                    if(paramUrl.length>0){
                        paramUrl=paramUrl.substring(1,paramUrl.length);
                        var paramUrlArray=paramUrl.split("&");
                        for(var i=0;i<paramUrlArray.length;i++){
                            if(paramUrlArray[i].toLowerCase().indexOf(paramName.toLowerCase())!=-1){
                                var temp=paramUrlArray[i].split("=");
                                if(temp[0].toLowerCase()==paramName.toLowerCase()){
                                    returnVal=temp[1];
                                    break;
                                }
                            }
                        }
                    }
                }
                catch(e){}
                return returnVal;
            }
    </script>
    <html>
    <body onload="YD(300,300,5000)">
    <input type="button" value="返回值" onclick="doSelect('code'+GetUrlParameter('param'))"/>
    </body>
    </html>
      

  2.   

    parent.document.getElementById("code1").value="dddd";
      

  3.   

    open:
    opener.document.getElementById("code1").value="dddd";
    iframe:
    parent.document.getElementById("code1").value="dddd";