您的位置:首页 > 其它

弹出窗口并将窗口中选择的值返回到父窗口中

2013-01-09 09:38 134 查看
在jsp页面中,通过访问一个action将获取的数据显示到一个子窗口中:

①引入c标签

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

②获取路径

<c:set var="context_path" value="${pageContext.request.contextPath}"/>

③打开窗口显示action获取的数据

<script type="text/javascript" src="js/jquery-1.8.1.js"></script>
<script type="text/javascript">
$(function(){
$("#openDialog").click(function(){
var context_path = document.getElementById("context_path").value;
var Height="510px";
var Width="700px";
/* 这句话有阻塞作用,当被打开的窗口关闭时var json=eval()这句话才会执行 */
var param = window.showModalDialog(context_path+"/action/deptQueryAction_getPageList", window, "dialogHeight:" + Height + ";dialogWidth:" + Width + ";center:yes;status:no;scroll:no");

var json = eval('(' + param + ')');
$("#returnValue").attr("value",json.id);//将打开窗口返回的值填写到父窗口中
});
});
</script>
<body>
<input type="button" id="openDialog">
<br>
<input type="text" id="returnValue">
</body>


④被打开的子窗口

<script type="text/javascript">
function dd(val1,val2)
{
var json = "{'id':'"+val1+"',name:'"+val2+"'}";
window.returnValue = json;
window.close();
}
</script>
<img src="<%=basePath%>resource/imgs/caozuo.jpg" onclick="dd(${item[0]},'${item[7]}');">

注意:如果需要在打开的子窗口中进行数据的查询,即需要再次访问action,并且将返回的数据显示到该子窗口中时,需要在<head></head>标签中添加:

<base target="_self"/>

在form标签中添加:target=“”

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息