showModalDialog用法:
1.jsp页面(父窗体页面)
function openW_(ID){
var time =new Date().getTime();
//关于加上那个 (new Data()) 是要避免showModalDialog页面自动缓存的问题,导致第二次打开页面,数据没有被刷新,这是因为showModalDialog页面如果每次的URL一样的话,它会自动显示以前在缓存里面的数据。

var url = 'itsmOndutyPlanWork-selectUser.action?date='+time+'&onduty_plan_id='+ID;
window.showModalDialog(url, self , "dialogHeight:600px; dialogWidth:400px");
}
//刷新当前页面
function loadDiv(){
var month = document.getElementById('month').value;
document.getElementById('itsmOndutyPlanWorkPage.month').value=month;
window.document.fm.submit(); //提交父窗体
<td class="centerContentTd">
<input type="button" value="修 改" class="mainButton" οnclick="openW_('${b.onduty_plan_id}');" >
</td>

2.action

public String selectUser()
{
String onduty_plan_id = this.httpServletRequest.getParameter("onduty_plan_id");
String ondutyUserIds = itsmOndutyPlanWorkService.getOndutyUserIds(onduty_plan_id);// 值班人ID串
String ondutyScheduleId=itsmOndutyPlanWorkService.getOndutyScheduleId(onduty_plan_id);
List<Map> list = itsmOndutyPlanWorkService.getUserListByScheduleId(ondutyScheduleId);
if (null != list && list.size() > 0) {
for (Map map : list) {
String USER_ID = String.valueOf(map.get("USER_ID"));

if (null != ondutyUserIds && !"".equals(ondutyUserIds)) {// 已设置值班人了
if (ondutyUserIds.indexOf(USER_ID) > -1) {// 如果包含某用户
map.put("isCheck", true);
} else {
map.put("isCheck", false);
}
} else {// 值班人为null
map.put("isCheck", false);
}
}// end for
}
this.httpServletRequest.setAttribute("list", list);

this.httpServletRequest.setAttribute("onduty_plan_id", onduty_plan_id);
return Action.SUCCESS;
}
3.selectUser.jsp

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/app.tld" prefix="a"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<a:head/>
<base target="_self">
<head>
<title>用户列表</title>

<SCRIPT type="text/javascript">
function subForm(){

var is_Have_Checked = false;//
var userIdBox = document.fm.userIdBox;
if(userIdBox){//存在时
var isUserIdBox_Len = userIdBox.length;
if(isUserIdBox_Len > 0){//多个时
//
for(var i=0 ; i<isUserIdBox_Len; i++){
if(userIdBox[i].checked){
is_Have_Checked = true;
break;
}
}
if(is_Have_Checked==false){
alert("还没有选择用户!");
userIdBox[0].focus();
return;
}

}else{//一个时
if(document.fm.userIdBox.checked = false){
alert("还没有选择用户!");
document.fm.userIdBox.focus();
return;
}
}
}else{//不存在时

}
fm.submit();
}
</SCRIPT>
</head>
<body οnlοad="general.addNbsp();" scroll="auto">
<form action="itsmOndutyPlanWork-editOnDutyUse.action" name="fm" method="post">
<input type="hidden" name="onduty_plan_id" value="${onduty_plan_id}">
<table class="queryResult">
<tr>
<td height="100%" valign="top">
<table class="fixed">
<tr class="fixedHeaderTr">
<td class="centerListTitle" width="5%">
<input type="checkBox" οnclick="general.selectAll()" />
</td>

<td class="centerListTitle">
<s:text name="用户名称"></s:text>
</td>
</tr>
<s:iterator value="#request.list" id="b">
<tr class="contentTr" οnmοuseοver="javascript:general.overColor();" οnmοuseοut="javascript:general.outColor();">
<td class="centerContentTd" width="5%">
<s:if test="#b.isCheck==true">
<input type="checkBox" name="userIdBox" value="${b.USER_ID}" checked="checked" οnclick="general.setAllBox()" />
</s:if>
<s:else>
<input type="checkBox" name="userIdBox" value="${b.USER_ID}" οnclick="general.setAllBox()" />
</s:else>
</td>
<td class="centerContentTd">
${b.USER_NAME}
</td>
</tr>
</s:iterator>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="center" height="30"><a:button text="提 交" οnclick="subForm();" /> &nbsp;&nbsp; <a:button text="关 闭" οnclick="window.close();" /></td>
</tr>

</table>
</form>
</body>
</html>
<a:foot/>

4.action
public void editOnDutyUse() {
String onduty_plan_id = this.httpServletRequest.getParameter("onduty_plan_id");
String[] userIdBox = this.httpServletRequest.getParameterValues("userIdBox");
String userIds = StringUtils.join(userIdBox, ";");
System.out.println("onduty_plan_id == " + onduty_plan_id);
System.out.println("userIds == " + userIds);
itsmOndutyPlanWorkService.editOnDutyUse(userIds, onduty_plan_id);
this.outPrintStrToPage("<script> window.close(); window.dialogArguments.loadDiv();</script>");
//执行完子窗体,子窗体提交后刷新父窗体,调用了父窗体的loadDiv()脚本方法,提交父窗体的表单

}

--------------------------------------------------------------------------------------------------------------------------------------------
在web开发中,经常会遇到需要弹出一个子窗口的情况,并且子窗口和父窗口之间需要保持良好的通信。如弹出一个子查询窗口,并把查询出的某项信息填充到父窗口的表单中,这时使用window对象的showModalDialog打开一个模态对话框来实现这一功能是非常有用的。
下面是一个简单示例

// src.html
<script type="text/javascript">
window.showModalDialog("des.html");
</script>

// des.html
<script type="text/javascript">
alert("this is des.html");
</script> 2. 为使打开的模态对话框的外观满足我们的要求,必须要设置对话框的样式。该方法的第三个参数可以用来设置我们需要的外观样式。

<script type="text/javascript">
window.showModalDialog("des.html", "", "dialogWidth: 600px; dialogHeight: 600px");
</script> 样式属性的设置是键值对的形式进行的,多个属性设置之间用分号“;”隔开。

可以设置的样式属性如下:

dialogHeight :对话框高度,不小于100pxpx,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
dialogWidth: 对话框宽度。
dialogLeft: 离屏幕左的距离。
dialogTop: 离屏幕上的距离。
center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。
下面几个属性是用在HTA中的,在一般的网页中一般不使用。
dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。
3. 但是最重要的在于如何向模态对话框中传递参数了,相信很多朋友都发现在上面的例子中showModalDialog方法的第二个参数为空字符串,其实我们就是通过它把信息传递到模态对话框中的。

// src.html
<script type="text/javascript">
window.showModalDialog("des.html", "my name is tuozixuan", "dialogWidth: 600px; dialogHeight: 600px");
</script>

在模态对话框窗体中需要用到window对象的dialogArguments属性来获取传递过来的参数(中英文字符都可)。

// des.html
<script type="text/javascript">
var msg = window.dialogArguments
alert(msg);
</script> 在向模态对话框传递参数时,不仅可以是字符串,还可以是Number、数组、对象等类型。

数字类型
// src.html
<script type="text/javascript">
window.showModalDialog("des.html", 1, "dialogWidth: 600px; dialogHeight: 600px");
</script>

// des.html
<script type="text/javascript">
var msg = window.dialogArguments
alert(msg);
</script>
数组类型
// src.html
<script type="text/javascript">
window.showModalDialog("des.html", [1,2,3], "dialogWidth: 600px; dialogHeight: 600px");
</script>

// des.html
<script type="text/javascript">
var msg = window.dialogArguments
alert(msg[2]);
</script> 对象类型
// src.html
<script type="text/javascript">
var obj = new Object();
obj.name = "tuozixuan";
obj.age = 1000;
window.showModalDialog("des.html", obj, "dialogWidth: 600px; dialogHeight: 600px");
</script>

// des.html
<script type="text/javascript">
var msgObj = window.dialogArguments;
alert(msgObj.name + " " + msgObj.age);
</script> 4. 模态对话框向父窗口传递信息

如果需要把模态对话框中的数据传递给父窗口中,需要用到模态对话框中window对象的returnValue属性。当用户关闭模态对话框时,浏览器将会把returnValue属性的值返回给父窗口,若该属性未设置,则返回undefined。

// src.html
<script type="text/javascript">
var obj = new Object();
obj.name = "tuozixuan";
obj.age = 1000;
var resultData = window.showModalDialog("des.html", obj, "dialogWidth: 600px; dialogHeight: 600px");
alert(resultData);
</script>

// des.html
<script type="text/javascript">
window.returnValue = "hello";
</script> 其中window对象的returnValue属性可以设置为数字、字符串、数字、对象等数据类型,情况和从父窗口向模态对话框中传递数据类似,在此不再赘述。

5. 模态对话框调用父窗口的js方法

可以把父窗口的window对象作为参数传递给模态对话框,模态对话框获取到参数对象的句柄后就可以调用父窗口的js方法了。

// src.html
<script type="text/javascript">
window.showModalDialog("des.html", window, "dialogWidth: 600px; dialogHeight: 600px");

function showMsg()
{
alert("飞雪连天射白鹿,笑书神侠倚碧鸳");
}
</script>

// des.html
<script type="text/javascript">
window.dialogArguments.showMsg();
</script>

当我们用showModelessDialog()打开窗口时,不必用window.close()去关闭它

转自:http://liminhappygirl.iteye.com/blog/1263467

showModalDialog用法相关推荐

  1. window.open和window.showModalDialog用法

    View Code window.open和window.showModalDialog用法2008/06/18 14:16一.window.open()支持环境: JavaScript1.0+/JS ...

  2. window.showModalDialog()用法

    1.定义 window.showModalDialog()用来创建模态对话框 语法为:vReturnValue = window.showModalDialog(sURL [, vArguments] ...

  3. window.showModalDialog()用法及注意事项

    今天在项目中用到了弹出子窗口,就想到了用JavaScript实现的两种方法,一个是window.open();一个是window.showModalDialog()方法,后者是存在父子关系的一种弹出窗 ...

  4. window.showModalDialog用法介绍

    基本介绍: showModalDialog() (IE 4+ 支持) showModelessDialog() (IE 5+ 支持) window.showModalDialog()方法用来创建一个显 ...

  5. js中showModalDialog函数用法

    showModalDialog用法: 1.jsp页面(父窗体页面) function openW_(ID){ var time =new Date().getTime(); //关于加上那个 (new ...

  6. 模式窗口showModalDialog的用法总结

    最近几天一直在处理模式窗口的问题,索性写了这篇总结,以供参考: 1.打开窗口: var handle = window.showModalDialog(url, objects, feathers); ...

  7. 模式窗口window.showModalDialog()的用法

    模式窗口的用法 一.问题: 我想弹出一个窗口,然后在弹出的窗口里,选择或输入一些信息,要求这些信息返回到父页面. 建立父页面:a.htm <html> <head>     & ...

  8. Chrome不支持showModalDialog的解决方案

    Chrome不支持showModalDialog的解决方案 昨天在使用showModalDialog的时候,遇到如下问题: 如果子窗口被刷新过,那么父窗口就接受不到子窗口的返回值. 为了解决这个问题, ...

  9. showModalDialog关闭子窗口,并刷新父窗口

    一.用法:window.showModalDialog(url,args,'dialogWidth=650px;scroll=no;dialogHeight=250px;status=no; '); ...

最新文章

  1. Mysql 的使用方式,挺全的够用了
  2. 新装 Win7 系统装完驱动精灵,一打开到检测界面就卡死——原因与解决方案
  3. 《代码大全2》读书笔记(七)
  4. Sourcing Cockpit: 2. Demo of Service Purchase Order
  5. oracle错误: ORA-00600: 内部错误代码, 参数: [kkqcscpopn_Int: 0], [], [], [], [], [], [], [], [], [], [], []...
  6. 面试问sql优化怎么回答
  7. android socket编程实例
  8. python写ini文件_Python读写ini文件
  9. C++day14 学习笔记
  10. 关机指令代码_iPhone这些隐藏代码你肯定不知道
  11. HDU 2154 跳舞毯
  12. 基于Handsome主题的站点页脚美化教程
  13. 网络操作系统 Linux配置与管理,网络操作系统—Linux配置与管理
  14. ADAUDSP1452 声场 Balance与Fader功能的实现
  15. win10查看显卡的运算能力
  16. 零基础入门学习Python 011列表:一个打了激素的数组2
  17. 【用户运营】滴滴出行活动策划、用户成长体系、用户增长逻辑分析
  18. [HarmonyOS][鸿蒙专栏开篇]快速入门OpenHarmony的LiteOS微内核
  19. 单片机的组成以及分类和指标
  20. markdown表格内如何进行换行

热门文章

  1. 万字长文解析:分布式架构、SOA、微服务架构、API网关、ESB服务总线架构之间的关联及演进
  2. 【JAVA】基础概念
  3. 类似Cryptonom的区块链游戏开发细节介绍
  4. 欧科云链研究院:5大常见区块链错误
  5. 【数据集】A Face Detection Benchmark
  6. 自学软件测试好找工作吗?
  7. python将多个3维数组转换成4维数组时,出现(m,)
  8. JAVAWEB开发模式之JSP的几种开发模式、处理Cookie中文乱码
  9. Android开发:WGS-84、GCJ02坐标名词解释及坐标转换
  10. 安装智能消费机服务器连接,中控消费机软件常见问题|中控CM20消费机教程