//在子窗体里使用Struts2标签<s:optiontransferselect/>
//也可在子窗体里使用<select id="rightId"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select> <input type="button" onclick="dy('rightId','/')"/>
//window.showModalDialog()有严重的缓存问题需要在"url?params="+new Date().getTime()或者随机数就可以解决次问题
//以解决了浏览器的兼容性问题
1、建立index.jsp文件(父窗体)
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>返回数据</title>
</head>
<body>
<script language="javascript">
function openWin(url,thisId){//父窗体
var status = "dialogwidth=500px;dialogheight=350px;status=no;help=no;scrollbars=no";
var result = window.showModalDialog(url,window,status);
if(result)
thisId.value = result;
}
</script>
<h1>子窗体传值给父窗体</h1>
<hr/>
1、<input type="text" name="text" id="text" size="70"
onclick="openWin('select.jsp',this);"/><br/>
2、<input type="text" name="text" id="text" size="70"
onclick="openWin('select.jsp',this);"/><br/>
3、<input type="text" name="text" id="text" size="70"
onclick="openWin('select.jsp',this);"/><br/>
</body>
</html>
2、建立select.jsp文件(子窗体)
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>数据选择</title>
</head>
<body>
<script type="text/javascript">
function dy(thisId,sign){//thisId子窗体ID,sign自定义连接符号
var rVal = "";
var rightId = document.getElementById(thisId);
for(var i = 0; i < rightId.length; i++){
rVal = rVal + sign + rightId.options[i].value;
}
if(rVal.charAt(0) == sign){
rVal = rVal.substring(1);
}
window.returnValue = rVal;
window.close();
}
</script>
<input type="button" value="click me" onclick="dy('rightId','/')" />
<s:optiontransferselect
label="白样单加工"
name="leftSideEmployeeRecords"
id="leftId"
leftTitle="被选加工用语"
list="{'A','B','C','D','E','F'}"
cssStyle="width:150px"
doubleName="rightSideEmployeeRecords"
rightTitle="已选加工用语"
doubleId="rightId"
doubleList="{}"
doubleCssStyle="width:150px"/>
</body>
</html>