ITeye博客

iframe assignRole

tree3170 · 2012-07-02 20:03 · Web · Jquery · Web前端 · Markdown

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. <tr >
  16. <td width="20%" >* Assigned Roles</td>
  17. <td width="80%" colspan="3" >
  18. <input type="hidden" value="" name="defaultRoleID">
  19. <input type="text" style="display:none;" value="" name="forCheckChangeDefRole">
  20. <input type="hidden" value="" name="roleIds">
  21. <table width="100%">
  22. <tbody>
  23. <tr>
  24. <td nowrap="" class="attributeContent" id="showRoleNames"></td>
  25. <td width="100%" id="roleNamesButton">
  26. <input type="button" onclick="javascript:getNames();" value="..." >
  27. </td>
  28. </tr>
  29. </tbody></table>
  30. </td>
  31. </tr>
  32. </table>
  33. </form>
  34. </body>
  35. </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. <form action="" name="main" method="post">
  14. <input type="hidden" value="1000" name="companyID">
  15. <table width="100%" cellspacing="1" cellpadding="0" border="0">
  16. <tbody><tr>
  17. <td width="100%" nowrap="" align="left" colspan="2" class="titleHeader">Assign Roles</td>
  18. </tr>
  19. <tr>
  20. <td width="50%" align="left" class="bodyBold"></td>
  21. <td width="50%" align="right">
  22. <input type="button" onclick="onClickOK();" value="OK" name="" class="button">
  23. <input type="button" onclick="javascript:top.close()" value="Close" name="" class="button">
  24. </td>
  25. </tr>
  26. <tr>
  27. <td height="2" colspan="2"></td>
  28. </tr>
  29. </tbody></table>
  30. <table width="100%" cellspacing="0" cellpadding="0" border="0">
  31. <tbody>
  32. <tr class="listViewThS1">
  33. <th width="24%" align="center">Default Role</th>
  34. <th width="76%">Assigned Roles</th>
  35. </tr>
  36. <tr>
  37. <td align="center"><input type="radio" checked="" id="radio0" value="1000" onclick="selectRadioBox('0');" name="defaultRole" style="width:15;height:15"></td>
  38. <td nowrap="" class="bodyBold">
  39. <img align="textTop" src="/suite/img/roles_t_spacer.gif">
  40. <input type="checkBox" disabled="" checked="" id="check0" value="1000" name="selectRoles" style="width:15;height:15">
  41. Company Administrator
  42. </td>
  43. <input type="hidden" id="roleName0" value="Company Administrator" name="roleName">
  44. </tr>
  45. <tr>
  46. <td align="center"><input type="radio" id="radio1" value="1010" name="defaultRole" onclick="selectRadioBox('1');" style="width:15;height:15"></td><
  47. td nowrap="" class="bodyBold">
  48. <img align="textTop" src="/suite/img/roles_t_spacer.gif">
  49. <input type="checkBox" id="check1" value="1010" name="selectRoles" style="width:15;height:15">
  50. <input type="hidden" id="roleName1" value="dev" name="roleName">
  51. </td></tr>
  52. <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">
  53. <img align="textTop" src="/suite/img/roles_l_spacer.gif">
  54. <input type="checkBox" id="check2" value="1011" name="selectRoles" style="width:15;height:15">
  55. qa
  56. <input type="hidden" id="roleName2" value="qa" name="roleName">
  57. </td></tr>
  58. </tbody></table>
  59. </form>
  60. </body>
  61. </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. function SaveObjParent(returnValue,obj){
  18. window.parent.returnValue=obj;
  19. }

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. }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。