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

来源:互联网 发布:淘宝联盟注册登录 编辑:程序博客网 时间:2024/05/04 22:59
在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=“”

 

原创粉丝点击