您的位置:首页 > 运维架构

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的形式为父页面赋值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: