- 浏览: 169369 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
静夜独窗:
有体会才真正明白
java break -
流浪若相惜:
你说的是在html文件吧?
如何在jsp文件中引入css和js文件 -
copyday:
really girl ??
showModalDialog用法 -
发呆的驴:
...
js中的push和join方法 -
itway:
thanks
JSP向后台传递参数的四种方式
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" onclick="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 onload="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" onclick="general.selectAll()" />
</td>
<td class="centerListTitle">
<s:text name="用户名称"></s:text>
</td>
</tr>
<s:iterator value="#request.list" id="b">
<tr class="contentTr" onmouseover="javascript:general.overColor();" onmouseout="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" onclick="general.setAllBox()" />
</s:if>
<s:else>
<input type="checkBox" name="userIdBox" value="${b.USER_ID}" onclick="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="提 交" onclick="subForm();" /> <a:button text="关 闭" onclick="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()去关闭它,
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" onclick="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 onload="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" onclick="general.selectAll()" />
</td>
<td class="centerListTitle">
<s:text name="用户名称"></s:text>
</td>
</tr>
<s:iterator value="#request.list" id="b">
<tr class="contentTr" onmouseover="javascript:general.overColor();" onmouseout="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" onclick="general.setAllBox()" />
</s:if>
<s:else>
<input type="checkBox" name="userIdBox" value="${b.USER_ID}" onclick="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="提 交" onclick="subForm();" /> <a:button text="关 闭" onclick="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()去关闭它,
发表评论
-
JS中Null与Undefined的区别以及""
2013-07-20 21:16 878JS中Null与Undefined的区别以及"&qu ... -
eval
2013-06-19 22:23 820eval()函数可计算某个字符串,并执行其中的的JavaScr ... -
javaScript放在<head>和<body>的区别
2013-04-03 11:47 2291javaScript放在<head>和<bo ... -
在HTML中嵌入Javasript的方法
2012-06-29 15:57 2248在HTML中嵌入Javascript的方法 1.直接在Java ... -
js初次加载页面的时候执行函数的方法
2012-06-08 09:57 2617(1) <html> <head> ... -
js 中利用触发事件 以提交表单的方式向后台传递数据
2012-05-07 10:42 2199function autoPb(){ var engin ... -
序号置换(自动生成select option 以及自动生成行和列)
2011-12-01 16:25 1227<html> <title> ... -
控件获得焦点时按回车触发一个js函数(event.keyCode)
2011-11-24 10:35 4066<!DOCTYPE HTML PUBLIC " ... -
表单元素checkbox点击文本区既可以选中
2011-11-17 09:14 874<label> <input type=&q ... -
js 代码段
2011-11-09 11:11 760<tr> <td colspan=&q ... -
js中的push和join方法
2011-11-09 10:30 7884<script type="text/java ... -
js数组 sort方法的分析
2011-10-29 14:11 2292在JavaScript中是没有数据类型的。因此在JavaScr ... -
innerTEXT与innerHTML的区别:
2011-10-14 16:54 1322innerHtml、innerText与outerHtml三者 ...
相关推荐
javascript代码模块之\Window.ShowModalDialog使用手册
项目中用到showModalDialog,总结一下使用心得与注意事项
window.showModalDialog的基本用法
本篇文章主要是对JS对话框_JS模态对话框showModalDialog的用法进行了总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助
showmodaldialog的用法收集,很詳細的。很好的東東,于大家一起分享
window.showModalDialog以及window.open用法简介
Selenium目前没有提供对IE模态对话框(即通过showModalDialog方法打开的弹出对话框)的处理。原因在于,模态对话框会将父页面的 JS挂起,直至对话框处理完毕才会继续执行父页面JS。因为Selenium的底层实现是基于JS的,...
window.showModalDialog以及window.open用法简介
ShowModalDialog函数的功能: 使用方法: 参数说明:
javascript代码模块之window.showModalDialog方法的使用
showModalDialog和showModelessDialog的用法,彼此之间有什么不同? 用事例进行说明。 如:对话框赋给父页面的值 步骤一:父页面CS文件Page_load中执行脚本(打开对话框) Button1.Attributes.Add("onclick","window...
使用window.showModalDialog的程序员都知道,该方法可返回值。但是如果遇到跨域时,就返回为underfine。本文档通过iframe镶嵌页面解决该问题。
做项目时,碰到了前台页面需要向弹出框传值并且需要使用弹出框的返回值的需要,一开始使用的prompt(); 发现ie浏览器时,prompt()弹出框的位置会固定在左上...后来使用window.showModalDialog(url,params,pos)方法 解决
使用方法: vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures]) vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures]) 参数说明: sURL -- 必选参数,类型:字符...
模态子画面详解 以及例程,转载与网络 希望能给大家提供帮助
本文实例讲述了JS中showModalDialog关闭子窗口刷新主窗口用法。分享给大家供大家参考,具体如下: 网上找了好长时间 大都是window.opener.location.reload(),等等 都不是我想要的 最后终于发现了一个 想知道的就往下...