window.open 通过子页面向父页面传值
2011-10-31 09:05
183 查看
父页面:
quoteAdd.vm
<tr>
<th width="95px;" align="right"><span style="color:red">* </span>搜索地名:</th>
<td>
<input type="text" name="search" id="search" />
<input type="button" value="搜索" name="tokenButton" onclick="openWindow()" class="btn-s"/>
</td>
</tr>
通过函数打开子页面
/**
* 打开新窗口
* 根据地名搜索出对应的结果
*/
function openWindow(){
var temp = $('#search').val();
if(null==temp || ""==temp){
alert('请输入要搜索的关键字!');
return;
}
/**返回四个值*/
var url = '.action?searchKey='+encodeURIComponent(temp);
window.open(url,'','resizable=true,height=400,width=500,top=240,left=340');
}
子页面:
searchArea.vm
<div class="wrapper">
<div class="area-w air"></div>
<div class="area-v"></div>
<div class="area">
<div style="text-align:right"></div>
<div class="area-w air"></div>
#set($fOptions={'width':'500px',"checkboxVal":'id',"url":"/area/searchArea.action?searchKey=$!{searchKey}"})
#set( $lstTitles = [
{'chn':'搜索结果', "eval":'#if($!{item.pppAreaName})$!{item.pppAreaName} > #end #if($!{item.ppAreaName})$!{item.ppAreaName} > #end #if($!{item.pAreaName})$!{item.pAreaName} > #end $!{item.areaName}','width':'380px'},
{'chn':'操作','eval':'<a href="#" onclick="getAreaData({preId:#if($!{item.pppid})$!{item.pppid}#else null #end,cityId:#if($!{item.ppid})$!{item.ppid}#else null #end,countyId:$!{item.pid},id:$!{item.id}},{cityName:$sQuote$!{item.ppAreaName}$sQuote,countyName:$sQuote$!{item.pAreaName}$sQuote,areaName:$sQuote$!{item.areaName}$sQuote})">选中</a>','width':'40px'}
])
#table($lstTitles $searchAreaList $fOptions)
</div>
<script type="text/javascript" src="$!{staticRoot}/js/aweb_base.js"></script>
<script type="text/javascript" src="$!{staticRoot}/js/common.js"></script>
<script type="text/javascript" src="$!{staticRoot}/js/quote/quote.js"></script>
</div>
通过链接向父页面传值getAreaData({ids},{areaNames})
根据子页面所父页面传的值为父页面设置值
function getAreaData(ids,areaNams){
var preId = null,cityId=null,countyId=null,townId=null;
var cityName = null,countyName = null,townName = null;
var defalutValue = '<option value="" selected="selected">---请选择---</option>';
$('select[name="quoteVo.preId"]',window.opener.document).val(preId);
$('#cityId',window.opener.document).html(defalutValue);
if(cityName!=null){
opt='<option value="' + cityId + '" selected="selected">' + cityName + '</option>';
$('#cityId',window.opener.document).html(opt);
}
$('#countyId',window.opener.document).html(defalutValue);
if(countyName!=null){
opt='<option value="' + countyId + '" selected="selected">' + countyName + '</option>';
$('#countyId',window.opener.document).html(opt);
}
$('#townId',window.opener.document).html(defalutValue);
if(townName!=null){
opt='<option value="' + townId + '" selected="selected">' + townName + '</option>';
$('#townId',window.opener.document).html(opt);
}
window.close();
}
整个过程完成,使用原生的js window.opener.documetn.getElementById('').value为父页面赋值时赋不上,所以改采用jquery的形式为父页面赋值
quoteAdd.vm
<tr>
<th width="95px;" align="right"><span style="color:red">* </span>搜索地名:</th>
<td>
<input type="text" name="search" id="search" />
<input type="button" value="搜索" name="tokenButton" onclick="openWindow()" class="btn-s"/>
</td>
</tr>
通过函数打开子页面
/**
* 打开新窗口
* 根据地名搜索出对应的结果
*/
function openWindow(){
var temp = $('#search').val();
if(null==temp || ""==temp){
alert('请输入要搜索的关键字!');
return;
}
/**返回四个值*/
var url = '.action?searchKey='+encodeURIComponent(temp);
window.open(url,'','resizable=true,height=400,width=500,top=240,left=340');
}
子页面:
searchArea.vm
<div class="wrapper">
<div class="area-w air"></div>
<div class="area-v"></div>
<div class="area">
<div style="text-align:right"></div>
<div class="area-w air"></div>
#set($fOptions={'width':'500px',"checkboxVal":'id',"url":"/area/searchArea.action?searchKey=$!{searchKey}"})
#set( $lstTitles = [
{'chn':'搜索结果', "eval":'#if($!{item.pppAreaName})$!{item.pppAreaName} > #end #if($!{item.ppAreaName})$!{item.ppAreaName} > #end #if($!{item.pAreaName})$!{item.pAreaName} > #end $!{item.areaName}','width':'380px'},
{'chn':'操作','eval':'<a href="#" onclick="getAreaData({preId:#if($!{item.pppid})$!{item.pppid}#else null #end,cityId:#if($!{item.ppid})$!{item.ppid}#else null #end,countyId:$!{item.pid},id:$!{item.id}},{cityName:$sQuote$!{item.ppAreaName}$sQuote,countyName:$sQuote$!{item.pAreaName}$sQuote,areaName:$sQuote$!{item.areaName}$sQuote})">选中</a>','width':'40px'}
])
#table($lstTitles $searchAreaList $fOptions)
</div>
<script type="text/javascript" src="$!{staticRoot}/js/aweb_base.js"></script>
<script type="text/javascript" src="$!{staticRoot}/js/common.js"></script>
<script type="text/javascript" src="$!{staticRoot}/js/quote/quote.js"></script>
</div>
通过链接向父页面传值getAreaData({ids},{areaNames})
根据子页面所父页面传的值为父页面设置值
function getAreaData(ids,areaNams){
var preId = null,cityId=null,countyId=null,townId=null;
var cityName = null,countyName = null,townName = null;
var defalutValue = '<option value="" selected="selected">---请选择---</option>';
$('select[name="quoteVo.preId"]',window.opener.document).val(preId);
$('#cityId',window.opener.document).html(defalutValue);
if(cityName!=null){
opt='<option value="' + cityId + '" selected="selected">' + cityName + '</option>';
$('#cityId',window.opener.document).html(opt);
}
$('#countyId',window.opener.document).html(defalutValue);
if(countyName!=null){
opt='<option value="' + countyId + '" selected="selected">' + countyName + '</option>';
$('#countyId',window.opener.document).html(opt);
}
$('#townId',window.opener.document).html(defalutValue);
if(townName!=null){
opt='<option value="' + townId + '" selected="selected">' + townName + '</option>';
$('#townId',window.opener.document).html(opt);
}
window.close();
}
整个过程完成,使用原生的js window.opener.documetn.getElementById('').value为父页面赋值时赋不上,所以改采用jquery的形式为父页面赋值
相关文章推荐
- 火狐里如何判断页面是否是通过window.open打开
- 通过window.open跳转得到上一个页面的URL
- 子页面是父页面通过window.open弹出
- window.open()方法,window.opener的用法,以及用该属性处理父子级页面的访问
- 个人笔记 js 01 js里window.open打开的子页面调用父页面的function
- 使用window.open()方法打开新页面,被浏览器拦截问题
- 在js中window.open通过“post”传递参数
- 「转载」window.open详解(javascript弹出页面)
- location.href、parent.location.href、top.location.href、 window.open实现页面跳转
- window.showModalDialog和window.open关闭子页面时刷新父页面
- location.href、parent.location.href、top.location.href、 window.open实现页面跳转
- 使用window.open()方式打开新页面,关闭后浏览器不能释放资源,需要等待主界面关闭后才能释放
- IE8下window.open 二次无法加载页面
- jquery 打开页面window.location和window.open的区别
- JS 用window.open()函数,父级页面如何取到子级页面的返回值?
- window.open与window.showModalDialog中主页面与从页面间的通信(原创)
- js 用 window.open()方法跳转到新页面并且用post方式传参
- 解决js中window.open弹出的是上次的缓存页面问题
- window.open 弹出页面回写父页面值及触发父页面Button事件
- 用window.open函数页面传值