父页面和子页面传值

父页面点击按钮,弹出子页面,子页面有一个list,怎么样才能在子页面关闭,关闭后将子页面的list传到父页面,在父页面获得list在显示list,最好有源码

可以这样:
[code="html"]
父页面


无标题页
<br> function opendialog1()<br> {<br> var someValue=window.showModalDialog(&quot;b.html&quot;,&quot;&quot;,&quot;dialogWidth=500px;dialogHeight=500px;status=no;help=no;scrollbars=no&quot;);<br> document.form1.p1t.value=someValue;<br> }</p> <pre><code>&lt;/script&gt; </code></pre> <p></head><br> <body><br> <form name="form1" action="#"><br> <input type="text" name="p1t"><br> <input type="button" value="打开对话框" onclick="opendialog1()"><br> </form><br> </body><br> </html></p> <p>子页面<br> <html><br> <head><br> <title>无标题页</title><br> <script language="javascript" type="text/javascript"><br> function a(wname)<br> {<br> parent.window.returnValue=wname; //父窗口就是上一个页面<br> window.close();<br> }<br>







[/code]

你可以自行改装一下,比如hello可能就是你要传的值。

在父页面写一个javascript 方法,例如:
function parentFun(a) {

// 假设父页面有一个文本框  id = "aaa"

document.getElementById("aaa").value = a;

}

在子页面调用父页面方法,并且把要传的值传入:
parent.parentFun("需要传的值");

我测试过 没问题的。

主窗口
[code="html"]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



New Document




<br> function openWin(){<br> window.open(&quot;child.html&quot;,&quot;&quot;,&quot;dialogWidth=500px;dialogHeight=500px;status=yes;help=no;scrollbars=no&quot;);//dialogWidth=500px;dialogHeight=500px;status=yes;help=no;scrollbars=no,设置窗口样式<br> }<br>









[/code]

子窗口
[code="html"]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



child

S<br> td<br> {<br> padding:2px 0px 2px 10px;<br> font-size:14px;<br> }<br>
<pre><code> function xx(){ var boxese = document.getElementsByName(&quot;danxuan&quot;); var boxxx_v = document.getElementById(&quot;vboxxx&quot;).value; if(boxxx_v!=&quot;null&quot;){ var boxxs = boxxx_v.split(&quot;,&quot;); for(var i=0;i&lt;boxese.length;i++){ for(var a=0;a&lt;boxxs.length;a++){ if(boxese[i].value==boxxs[a]) boxese[i].checked = true; } } } } </code></pre> <p>function submitform(){<br> /*****<br> var checkboxvalue = &quot;&quot;;<br> var box = document.form11.danxuan;<br> for(var i=0;i&lt;box.length;i++){<br> if(box[i].checked==true){<br> checkboxvalue=box[i].value;<br> }<br> }<br> if(checkboxvalue==&quot;&quot;){<br> alert(&quot;请选择...&quot;);<br> return false;<br> }else{<br> window.opener.form11.textfield2.value=checkboxvalue;<br> window.close();<br> }</p> <pre><code> ****/ var val = document.getElementById(&quot;vboxxx&quot;).value; var ZONE = &quot;A&quot;; //alert(val); //alert(ZONE); //处理val控制和null val = (val==&quot;null&quot;)?&quot;&quot;:val; //alert(val); if(ZONE==&quot;A&quot;){//A端 //alert(ZONE); window.opener.form11.fullname.value=val; //alert(window.opener.form11.ELESA.value); }else if(ZONE=&quot;B&quot;)//B端 { //alert(ZONE); window.opener.form11.fullname.value=val; //alert(window.opener.form11.ELESB.value); } window.close(); } var vbox=&quot;&quot;; var spl=&quot;,&quot;; //分页跳转函数 </code></pre> <p>function GotoPageSubmit(GotoPage)<br> {</p> <pre><code> vbox=&quot;&quot;; var boxxx = document.getElementById(&quot;vboxxx&quot;).value; //var curBox = document.getElementById(&quot;curBox&quot;).value; var boxes = document.getElementsByName(&quot;danxuan&quot;); /**** for(var i=0;i&lt;boxes.length;i++) if(boxes[i].checked==true){ vbox += boxes[i].value; vbox += spl; } if(boxxx!=&quot;null&quot;) vbox +=boxxx; *****/ /***** if(vbox==&quot;null&quot;){ vbox = &quot;&quot;; } document.getElementById(&quot;vboxxx&quot;).value =boxxx.concat(curBox); var boxxx1 = document.getElementById(&quot;vboxxx&quot;).value; ***/ //form11.mingcheng.value = trim(form11.mingcheng.value); </code></pre> <p>form11.currentPage.value = GotoPage;<br> form11.submit();<br> }</p> <p>function boxClick(obj){</p> <pre><code> vbox=&quot;&quot;; var boxxx = document.getElementById(&quot;vboxxx&quot;).value; var boxes = document.getElementsByName(&quot;danxuan&quot;); //alert(vbox); //alert(boxxx); for(var i=0;i&lt;boxes.length;i++) { if(boxes[i].checked==true){ vbox += boxes[i].value; //alert(boxes[i].value); vbox += spl; } } //alert(&quot;遍历完毕&quot;); if(boxxx!=&quot;null&quot;){ vbox += boxxx; } //首先清空document.getElementById(&quot;vboxxx&quot;).value值 //document.getElementById(&quot;vboxxx&quot;).value = &quot;&quot;; //document.getElementById(&quot;vboxxx&quot;).value =vbox; //var s = &quot;5CBF677D07CB4CBC9CA003F012AADDF5,5CBF677D07CB4CBC9CA003F012AADDF5,7924E93A36A84B0FBDF9FA00BD06D99A,&quot;; var arr = vbox.split(spl); //alert(arr); //清空Hashtable //hashCompany.clear(); FillData(arr); //alert(hashCompany._count); //alert(GetDataFromHash()); /**** *判断当前是否选中,如果选中检查Hatable中是否存在 *如果存在,不再添加,如果不存在则添加数据 ****/ var currentValue = obj.value; var isChecked = obj.checked; if(!isChecked) { //没有选中或取消选中 hashCompany.remove(currentValue); } else { hashCompany.add(currentValue,currentValue); } //alert(&quot;数据处理完毕&quot;); //alert(GetDataFromHash()); document.getElementById(&quot;vboxxx&quot;).value =GetDataFromHash(); </code></pre> <p>// document.getElementById(&quot;vboxxx&quot;).value =GetDataFromHash().concat(spl);</p> <pre><code> var boxxx1 = document.getElementById(&quot;vboxxx&quot;).value; //清空vobx值 vbox=&quot;&quot;; </code></pre> <p>}</p> <p>function tabKey_to_enterKey()<br> {<br> if(event.keyCode==13){<br> event.keyCode=9;<br> GotoPageSubmit(1);<br> }<br> }</p> <p>document.onkeydown=tabKey_to_enterKey;</p> <p>














                    <tr class="TableHeader" align="center">
                        <td ><input name="mingcheng" type="text" value="" /></td>
                        <td>
                        <input type="button" value="查询" class="BigButton" onclick="GotoPageSubmit(1);">&nbsp;&nbsp;
                        <input name="queding" type="button" onClick="submitform();" class="BigButton" value="确定">
                        &nbsp;&nbsp;
                        <input type="button" value="关闭" class="BigButton"
                            onclick="window.close();">                          </td>
                    </tr>
                </tbody>
            </table>
            <br>
        </div>

        <table width="50%" border="0" cellspacing="1">
          <tr >
            <td colspan="8" align="center" valign="middle" bgcolor="#999999">A端现场标签 </td>
          </tr>

          <tr bgcolor="#C6E1FD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="5C9A4B7F9C1D4D3189F3C51331DD2F2C">
            </td>
            <td align="left">国棉四厂72号楼光分纤箱</td>
          </tr>

          <tr bgcolor="#DBECFD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="CCBCF59974BE47AC8000AE470382CCBF">
            </td>
            <td align="left">财源大厦地下室光分纤箱</td>
          </tr>

          <tr bgcolor="#C6E1FD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="8511A485284443A7886ACF73414D1796">
            </td>
            <td align="left">中医院高层住宅楼2单元负一层光分纤箱</td>
          </tr>

          <tr bgcolor="#DBECFD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="AA5514ECC59244C1A29B940626A373E6">
            </td>
            <td align="left">电器电机厂办公楼光分纤箱</td>
          </tr>

          <tr bgcolor="#C6E1FD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="29940697907C490DAD650C9C1C775FE7">
            </td>
            <td align="left">电器电机厂家属楼1单元光分纤箱</td>
          </tr>

          <tr bgcolor="#DBECFD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="B79EBC24048743A6AFFECDB6E1B6C428">
            </td>
            <td align="left">电器电机厂家属楼2单元光分纤箱</td>
          </tr>

          <tr bgcolor="#CCCCCC">
            <td colspan="8" align="center" valign="middle">共8条记录 共2页1 <a href="javascript:GotoPageSubmit(2)">2 </a></td>
          </tr>
        </table>
        </form>     
        </td>
    </tr>
  </tbody>
</table>



[/code]

需要的JS代码
[code="js"]
//=============
//Hashtable
//=============
function Hashtable()
{
this._hash = {};
this._count = 0;
this.add = function(key, value)
{
if (this._hash.hasOwnProperty(key)) return false;
else { this._hash[key] = value; this._count++; return true; }
}
this.remove = function(key) { delete this._hash[key]; this._count--; }
this.count = function() { return this._count; }
this.items = function(key) { if (this.contains(key)) return this._hash[key]; }
this.contains = function(key) { return this._hash.hasOwnProperty(key); }
this.clear = function() { this._hash = {}; this._count = 0; }
}

var hashCompany = new Hashtable();

function FillData(arr) {

hashCompany.clear();

for (var i = 0; i < arr.length; i++) {

if (arr[i] != "") {

t = arr[i].split("'");

        if (t.length > 2)
        {   
            if (!hashCompany.contains(t[0].trim()))
            {   
                hashCompany.add(t[0].trim(), t[1]);   
            }   
        } 
        else
        {
          if (!hashCompany.contains(arr[i].trim()))
            {   
                hashCompany.add(arr[i].trim(), arr[i].trim());   
            }   
        }
    }   
}   

}

function GetDataFromHash() {

var s = "";

if (hashCompany._count > 0) {

for (var i in hashCompany._hash) {

s += i + ",";

}

}

if (s.length > 0) {

s = s.substring(0, s.length - 1);

}

return s;

}

String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }

//FillData(arr);
//alert(hashCompany._count);
//alert(GetDataFromHash());
[/code]

子窗口可以分页,这个需要你自己修改。同时,当分页分别选中的,又想取消选中,这个可以很好处理,同时保存上页选中的内容。已经测试过。在IE6可以运行。

子窗口
[code="html"]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



New Document




<br> function openWin(){<br> window.open(&quot;child.html&quot;,&quot;&quot;,&quot;dialogWidth=500px;dialogHeight=500px;status=yes;help=no;scrollbars=no&quot;);//dialogWidth=500px;dialogHeight=500px;status=yes;help=no;scrollbars=no,设置窗口样式<br> }<br>








[/code]

child.html
[code="html"]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



child

S<br> td<br> {<br> padding:2px 0px 2px 10px;<br> font-size:14px;<br> }<br>
<pre><code> function xx(){ var boxese = document.getElementsByName(&quot;danxuan&quot;); var boxxx_v = document.getElementById(&quot;vboxxx&quot;).value; if(boxxx_v!=&quot;null&quot;){ var boxxs = boxxx_v.split(&quot;,&quot;); for(var i=0;i&lt;boxese.length;i++){ for(var a=0;a&lt;boxxs.length;a++){ if(boxese[i].value==boxxs[a]) boxese[i].checked = true; } } } } </code></pre> <p>function submitform(){<br> /*****<br> var checkboxvalue = &quot;&quot;;<br> var box = document.form11.danxuan;<br> for(var i=0;i&lt;box.length;i++){<br> if(box[i].checked==true){<br> checkboxvalue=box[i].value;<br> }<br> }<br> if(checkboxvalue==&quot;&quot;){<br> alert(&quot;请选择...&quot;);<br> return false;<br> }else{<br> window.opener.form11.textfield2.value=checkboxvalue;<br> window.close();<br> }</p> <pre><code> ****/ var val = document.getElementById(&quot;vboxxx&quot;).value; var ZONE = &quot;A&quot;; //alert(val); //alert(ZONE); //处理val控制和null val = (val==&quot;null&quot;)?&quot;&quot;:val; //alert(val); if(ZONE==&quot;A&quot;){//A端 //alert(ZONE); window.opener.form11.fullname.value=val; //alert(window.opener.form11.ELESA.value); }else if(ZONE=&quot;B&quot;)//B端 { //alert(ZONE); window.opener.form11.fullname.value=val; //alert(window.opener.form11.ELESB.value); } window.close(); } var vbox=&quot;&quot;; var spl=&quot;,&quot;; //分页跳转函数 </code></pre> <p>function GotoPageSubmit(GotoPage)<br> {</p> <pre><code> vbox=&quot;&quot;; var boxxx = document.getElementById(&quot;vboxxx&quot;).value; //var curBox = document.getElementById(&quot;curBox&quot;).value; var boxes = document.getElementsByName(&quot;danxuan&quot;); /**** for(var i=0;i&lt;boxes.length;i++) if(boxes[i].checked==true){ vbox += boxes[i].value; vbox += spl; } if(boxxx!=&quot;null&quot;) vbox +=boxxx; *****/ /***** if(vbox==&quot;null&quot;){ vbox = &quot;&quot;; } document.getElementById(&quot;vboxxx&quot;).value =boxxx.concat(curBox); var boxxx1 = document.getElementById(&quot;vboxxx&quot;).value; ***/ //form11.mingcheng.value = trim(form11.mingcheng.value); </code></pre> <p>form11.currentPage.value = GotoPage;<br> form11.submit();<br> }</p> <p>function boxClick(obj){</p> <pre><code> vbox=&quot;&quot;; var boxxx = document.getElementById(&quot;vboxxx&quot;).value; var boxes = document.getElementsByName(&quot;danxuan&quot;); //alert(vbox); //alert(boxxx); for(var i=0;i&lt;boxes.length;i++) { if(boxes[i].checked==true){ vbox += boxes[i].value; //alert(boxes[i].value); vbox += spl; } } //alert(&quot;遍历完毕&quot;); if(boxxx!=&quot;null&quot;){ vbox += boxxx; } //首先清空document.getElementById(&quot;vboxxx&quot;).value值 //document.getElementById(&quot;vboxxx&quot;).value = &quot;&quot;; //document.getElementById(&quot;vboxxx&quot;).value =vbox; //var s = &quot;5CBF677D07CB4CBC9CA003F012AADDF5,5CBF677D07CB4CBC9CA003F012AADDF5,7924E93A36A84B0FBDF9FA00BD06D99A,&quot;; var arr = vbox.split(spl); //alert(arr); //清空Hashtable //hashCompany.clear(); FillData(arr); //alert(hashCompany._count); //alert(GetDataFromHash()); /**** *判断当前是否选中,如果选中检查Hatable中是否存在 *如果存在,不再添加,如果不存在则添加数据 ****/ var currentValue = obj.value; var isChecked = obj.checked; if(!isChecked) { //没有选中或取消选中 hashCompany.remove(currentValue); } else { hashCompany.add(currentValue,currentValue); } //alert(&quot;数据处理完毕&quot;); //alert(GetDataFromHash()); document.getElementById(&quot;vboxxx&quot;).value =GetDataFromHash(); </code></pre> <p>// document.getElementById(&quot;vboxxx&quot;).value =GetDataFromHash().concat(spl);</p> <pre><code> var boxxx1 = document.getElementById(&quot;vboxxx&quot;).value; //清空vobx值 vbox=&quot;&quot;; </code></pre> <p>}</p> <p>function tabKey_to_enterKey()<br> {<br> if(event.keyCode==13){<br> event.keyCode=9;<br> GotoPageSubmit(1);<br> }<br> }</p> <p>document.onkeydown=tabKey_to_enterKey;</p> <p>














                    <tr class="TableHeader" align="center">
                        <td ><input name="mingcheng" type="text" value="" /></td>
                        <td>
                        <input type="button" value="查询" class="BigButton" onclick="GotoPageSubmit(1);">&nbsp;&nbsp;
                        <input name="queding" type="button" onClick="submitform();" class="BigButton" value="确定">
                        &nbsp;&nbsp;
                        <input type="button" value="关闭" class="BigButton"
                            onclick="window.close();">                          </td>
                    </tr>
                </tbody>
            </table>
            <br>
        </div>

        <table width="50%" border="0" cellspacing="1">
          <tr >
            <td colspan="8" align="center" valign="middle" bgcolor="#999999">A端现场标签 </td>
          </tr>

          <tr bgcolor="#C6E1FD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="5C9A4B7F9C1D4D3189F3C51331DD2F2C">
            </td>
            <td align="left">国棉四厂72号楼光分纤箱</td>
          </tr>

          <tr bgcolor="#DBECFD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="CCBCF59974BE47AC8000AE470382CCBF">
            </td>
            <td align="left">财源大厦地下室光分纤箱</td>
          </tr>

          <tr bgcolor="#C6E1FD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="8511A485284443A7886ACF73414D1796">
            </td>
            <td align="left">中医院高层住宅楼2单元负一层光分纤箱</td>
          </tr>

          <tr bgcolor="#DBECFD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="AA5514ECC59244C1A29B940626A373E6">
            </td>
            <td align="left">电器电机厂办公楼光分纤箱</td>
          </tr>

          <tr bgcolor="#C6E1FD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="29940697907C490DAD650C9C1C775FE7">
            </td>
            <td align="left">电器电机厂家属楼1单元光分纤箱</td>
          </tr>

          <tr bgcolor="#DBECFD" align="center">
            <td align="center" style="width:10%">
            <input name="danxuan" type="checkbox" onclick="boxClick(this);" value="B79EBC24048743A6AFFECDB6E1B6C428">
            </td>
            <td align="left">电器电机厂家属楼2单元光分纤箱</td>
          </tr>

          <tr bgcolor="#CCCCCC">
            <td colspan="8" align="center" valign="middle">共8条记录 共2页1 <a href="javascript:GotoPageSubmit(2)">2 </a></td>
          </tr>
        </table>
        </form>     
        </td>
    </tr>
  </tbody>
</table>



[/code]