回调
来源:互联网 发布:淘宝中国质造质量 编辑:程序博客网 时间:2024/05/04 14:07
一、window.open方法
在A.jsp页面点击“输入Email”按钮,会调用js方法,开启一个子窗口B;输入完毕“确定”会将输入值回传到父窗口栏位显示。
(1)A.js方法:
function openEmailWin(){var url=ctx+"/mvc/B.jsp?callBackFunction=userEmailCallBack";width=450;height=90;LeftPosition=(screen.width)?(screen.width-width)/2:0;TopPosition=(screen.height)?(screen.height-height)/2:0;emailWin=window.open(url, null, "height="+height+",width="+width+",top="+TopPosition+",left="+LeftPosition);
function userEmailCallBack(emailObject){if(emailObject!=null){ document.getElementById('userEmail').value=emailObject.userEmail;}}(2)B.jsp
<form id="form1" name="form1" method="POST"><ul><li class="e1"><span>Email :</span></li><li><input name="userEmail" id="userEmail" type="email" apply="true" val="{allowBlank:false,blankText:'Email不能为空!'}" /><input type="hidden" id="callbackFunction" name="callbackFuction" value="<%=request.getParameter("callBackFunction")%>"></input></li><li><input type="button" id="okButton" onclick="emailWin()" value="确定"></input> <input type="button" id="canelButton" onclick=" window.close()" value="取消"></input> </li></ul></form>(3)B.js
function emailWin(){if(opener&&!opener.closed){var callback;var callbackElem=document.getElementById('callbackFunction');var emailObject={};emailObject.userEmail=document.getElementById('userEmail').value;callback=opener[callbackElem.value];callback(emailObject);}window.close();}
二、openSubWnd方法
(1)A.js
function openIPlanNewIPWnd() {var url = ctx + "/mvc/B.do";openSubWnd("BWnd","BWnd",1000,600,url,bCallBack);}function bCallBack(object) {if(object != null) { document.getElementById("userid").value = object.userID; document.getElementById("email").value = object.email; document.getElementById("age").value = object.age; }}(2)B.js
function callBackObject() {var win= window.parent.Ext.getCmp('BWnd');if(win) {if(document.getElementById("isOK").value=="ok"){var callBack;var object = {};object.userID = document.getElementById("userid").value;object.email = document.getElementById("email").value;.。。。win.callBack(object);win.close();}else{document.getElementById("isOK").value="";}}}
0 0