`

iframe assignRole

 
阅读更多

 

frame嵌套操作:点击按钮--》弹出对话框(嵌套iframe)--》取得iframe值,并保存在parent对象中,点击ok--》在原页面取得选中的值(回填)

test.jsp(button-->click)-->test1.jsp(iframe -->popup.jsp)  

test.jsp

 

[html] view plaincopy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="ISO-8859-1"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">  
  7. <title>Insert title here</title>  
  8. <script type="text/javascript" src="js/jquery-1.7.1.js"></script>  
  9. <script type="text/javascript" src="js/test.js"></script>  
  10. </head>  
  11. <body>  
  12. username:<input name="username" type="text"> <input type="button" name="popup" onclick="javascript:getNames()">  
  13. <form method="post" action="/suite/EditUserAction.do" name="frmEditUser">  
  14.     <table>  
  15.       
  16.     <tr >  
  17.         <td width="20%" >* Assigned Roles</td>  
  18.         <td width="80%" colspan="3" >  
  19.             <input type="hidden" value="" name="defaultRoleID">  
  20.             <input type="text" style="display:none;" value="" name="forCheckChangeDefRole">  
  21.             <input type="hidden" value="" name="roleIds">  
  22.             <table width="100%">  
  23.                 <tbody>  
  24.                 <tr>  
  25.                     <td nowrap="" class="attributeContent" id="showRoleNames"></td>  
  26.                     <td width="100%" id="roleNamesButton">  
  27.                     <input type="button" onclick="javascript:getNames();" value="..." >  
  28.                     </td>  
  29.                 </tr>  
  30.             </tbody></table>  
  31.         </td>  
  32.     </tr>  
  33.     </table>  
  34. </form>  
  35. </body>  
  36. </html>  

test1.jsp

[html] view plaincopy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="utf-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  7. <title>Insert title here</title>  
  8. <script type="text/javascript" src="js/jquery-1.7.1.js"></script>  
  9. <script type="text/javascript" src="js/test.js"></script>  
  10. </head>  
  11. <body>  
  12. 用户名<input name="username" type="text"> <input type="button" name="popup">  
  13. <iframe width="100%" scrolling="auto" height="1000" frameborder="0"  name="assignRoleFrame" src="popup.jsp"></iframe>  
  14. </body>  
  15. </html>  

popup.jsp

 

[html] view plaincopy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="utf-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">  
  7. <title>Insert title here</title>  
  8. </head>  
  9. <script language="javascript" src="js/open.js"> </script>  
  10. <body>  
  11. assignRoles:  
  12. <input type="text" name="username">  
  13.   
  14.   
  15. <form action="" name="main" method="post">  
  16. <input type="hidden" value="1000" name="companyID">  
  17. <table width="100%" cellspacing="1" cellpadding="0" border="0">  
  18.     <tbody><tr>  
  19.         <td width="100%" nowrap="" align="left" colspan="2" class="titleHeader">Assign Roles</td>  
  20.     </tr>  
  21.     <tr>  
  22.         <td width="50%" align="left" class="bodyBold"></td>  
  23.         <td width="50%" align="right">  
  24.             <input type="button" onclick="onClickOK();" value="OK" name="" class="button">  
  25.             <input type="button" onclick="javascript:top.close()" value="Close" name="" class="button">  
  26.         </td>  
  27.     </tr>  
  28.     <tr>  
  29.         <td height="2" colspan="2"></td>  
  30.     </tr>  
  31.     </tbody></table>  
  32. <table width="100%" cellspacing="0" cellpadding="0" border="0">  
  33.   <tbody>  
  34.     <tr class="listViewThS1">  
  35.         <th width="24%" align="center">Default Role</th>  
  36.   
  37.         <th width="76%">Assigned Roles</th>  
  38.     </tr>  
  39.        
  40.   
  41.     
  42.    <tr>  
  43.         <td align="center"><input type="radio" checked="" id="radio0" value="1000" onclick="selectRadioBox('0');" name="defaultRole" style="width:15;height:15"></td>  
  44.            <td nowrap="" class="bodyBold">  
  45.              
  46.              <img align="textTop" src="/suite/img/roles_t_spacer.gif">  
  47.                  
  48.            <input type="checkBox" disabled="" checked="" id="check0" value="1000" name="selectRoles" style="width:15;height:15">  
  49.            Company Administrator  
  50.             </td>  
  51.             <input type="hidden" id="roleName0" value="Company Administrator" name="roleName">  
  52.    </tr>  
  53.      
  54.     <tr>  
  55.     <td align="center"><input type="radio" id="radio1" value="1010" name="defaultRole" onclick="selectRadioBox('1');" style="width:15;height:15"></td><  
  56.     td nowrap="" class="bodyBold">  
  57.     <img align="textTop" src="/suite/img/roles_t_spacer.gif">  
  58.     <input type="checkBox" id="check1" value="1010" name="selectRoles" style="width:15;height:15">  
  59.     <input type="hidden" id="roleName1" value="dev" name="roleName">  
  60.     </td></tr>  
  61.     <tr><td align="center"><input type="radio" id="radio2" value="1011" name="defaultRole" onclick="selectRadioBox('2');" style="width:15;height:15"></td><td nowrap="" class="bodyBold">  
  62. <img align="textTop" src="/suite/img/roles_l_spacer.gif">  
  63. <input type="checkBox" id="check2" value="1011" name="selectRoles" style="width:15;height:15">  
  64. qa  
  65. <input type="hidden" id="roleName2" value="qa" name="roleName">  
  66. </td></tr>  
  67.   
  68. </tbody></table>  
  69. </form>  
  70. </body>  
  71. </html>  

test.js

 

 

[javascript] view plaincopy
  1. function getNames(){  
  2.     var properties = 'toolbar:no;menubar:no;scrollbars:no;resizable:no;dialogHeight:550px;dialogWidth:480px';  
  3.     var url = "/test/test1.jsp";  
  4.     var DialogArgument = new Object();  
  5.     DialogArgument["src"] = url;  
  6.     DialogArgument["title"] = "Assigned Roles";  
  7.     var oValue = showModalDialog(url, DialogArgument, properties);   
  8.     if(oValue!=null){  
  9.         $("input[name=defaultRoleID]").val(oValue.defaultRole);  
  10.         $("input[name=roleIds]").val(oValue.roleIds);  
  11.         $("input[name=username]").val(oValue.roleNames);  
  12.         var button=document.getElementById("roleNamesButton").innerHTML;  
  13.         document.getElementById("roleNamesButton").innerHTML=oValue.roleNames+button;  
  14.     }  
  15.     return true;   
  16. }  
  17.   
  18. function SaveObjParent(returnValue,obj){  
  19.     window.parent.returnValue=obj;  
  20. }  

open.js

 

 

[javascript] view plaincopy
  1. function selectRadioBox(id){  
  2.     document.getElementById("check"+id).checked=true;   
  3.     document.getElementById("check"+id).disabled=true;  
  4.     var checkbox=document.getElementsByName("selectRoles");  
  5.     for(var i=0;i<checkbox.length;i++){  
  6.         if(i!=id)  
  7.             checkbox[i].disabled=false;  
  8.     }  
  9. }  
  10. function onClickOK(){  
  11.     var returnRoles=new Object();  
  12.     var returnValue;  
  13.     var onSelectedRadio=document.getElementsByName("defaultRole");  
  14.     var selectRoleId=document.getElementsByName("selectRoles");  
  15.     var selectRoleName=document.getElementsByName("roleName");  
  16.     var roleIds="";  
  17.     var roleNames="";  
  18.     var defaultRoleID="";  
  19.     var j=0;  
  20.     for(var i=0;i<onSelectedRadio.length;i++){  
  21.         if(onSelectedRadio[i].checked){  
  22.             defaultRoleID=onSelectedRadio[i].value;  
  23.             roleIds=selectRoleId[i].value+roleIds;  
  24.             roleNames=selectRoleName[i].value+"(<font color='red'>Default</font>)"+roleNames;  
  25.         }  
  26.         else if(selectRoleId[i].checked){  
  27.                 roleIds=roleIds+","+selectRoleId[i].value;  
  28.                 roleNames=roleNames+","+selectRoleName[i].value;  
  29.         }  
  30.     }  
  31.     if(defaultRoleID==""){  
  32.         alert("Please select default role.");  
  33.         return;  
  34.     }  
  35.     returnRoles.defaultRole=defaultRoleID;  
  36.     returnRoles.roleIds=roleIds;  
  37.     returnRoles.roleNames=roleNames;  
  38.     var obj=returnRoles;  
  39.     window.parent.SaveObjParent(returnValue,obj);  
  40.     window.parent.close();  
  41. }  


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics