当前位置:编程学习 > JS >>

js实现父页面接收子页面传的值

一:父页面

1:校对人员编号文本框代码:

[html] <input name="txtJDRY" type="text" id="txtJDRY" size="10" maxlength="40" readonly="readonly" value="${requestScope.txtGetYhbh }" class="ReadonlyText"/> 

\
2:查找编号按钮代码:

[html]
<input type="button" name="Button2" value="查找编号" onClick="SearchCode()" accesskey="Q" style="cursor='hand'"/> 
3:查找编号按钮所调用的js方法:SearchCode(),当点击查找编号按钮之后弹出如下图片:

[html]
function SearchCode(){ 
        var wndMEPImgPreView=window.open("<%=basePath%>cxaction.do?action=cxJDRY","wndMEPImgPreView","toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600,left=200,top=200"); 
        wndMEPImgPreView.focus(); 
    } 
二:子页面

\
1:选中其中的一个单选按钮,点击添加编号按钮会将选中的用户编号传到父页面

其中这个页面的js代码如下:

button按钮:
[html]
<input name="btnquery" type="button" id="btnquery" value="   添加编号   " style="cursor='hand'" onclick="win()"> 
js  win()方法:

[html]
function win(){ 
       var radios = document.getElementsByTagName("input"); 
        for(var i = 0 ;i<radios.length ; i++){ 
            if(radios[i].type=="radio"   && radios[i].checked){ 
                window.opener.document.getElementById("txtJDRY").value=radios[i].value;//txtJDRY是要显示在父页面中那个文本框里的文本框的id 
            } 
        } 
       window.close(); 
    } 
2:当点击添加编号按钮之后,会将你选中的单选框中的用户编号传入父页面的文本框中 例如:选中编号为21,图如下:

 \

 

摘自 天易LoveZLL

补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,