window.open 通过子页面向父页面传值

父页面:

quoteAdd.vm

  <tr>
      <th width="95px;" align="right"><span style="color:red">*&nbsp;</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的形式为父页面赋值

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值