父页面:
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" οnclick="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="#" οnclick="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的形式为父页面赋值