您的位置:首页 > Web前端 > JQuery

ajax+jquery实现父页面弹出子页面,选择提交后给父页面传值

2016-04-21 13:57 573 查看
父页面


<scripttype="text/javascript">

  //obj是父页面点击的控件
functionopenRecord(obj){
varurl="provider!select.do";//执行后台url
varprop='dialogWidth:980px;dialogHeight:500px;dialogLeft:200px;'+
'dialogTop:150px;resizable:no;center:yes;status:yes';

//改变id,供子页面获取
obj.id="proNumSelect";
    //先改变tr的值,让子页面定位到该tr
obj.parentNode.parentNode.id="trSelect";
$("#trSelectinput[id='providerFullnames']").attr('id','proFullnameSelect');
$("#trSelectinput[id='proId']").attr('id','proIdSelect');

varopenWindows=window.open(url,window,prop);
}
</script>


子页面


<scripttype="text/javascript">
functionfnParent(){
//window.opener.location.reload();//刷新父窗口
window.close();
}
functiononSelected(){
varproIds=document.getElementsByName("providerId");
varproId="";
for(vari=0;i<proIds.length;i++){
if(proIds[i].checked)
proId=proIds[i].value;
}
if(proId.length!=0){
$.ajax({
type:'post',
url:'provider!setChileValue.do',//调用的方法
data:'proId='+proId,
success:function(data){
varproMap=eval(data);//转换数组

//给父窗口传值
window.opener.document.getElementById("proIdSelect").value=proMap[0].proId;
window.opener.document.getElementById("proNumSelect").value=proMap[0].proNumber;
window.opener.document.getElementById("proFullnameSelect").value=proMap[0].proFullname;

//将父窗口id恢复原来的
window.opener.document.getElementById("trSelect").id="";
window.opener.document.getElementById("proIdSelect").id="proId";
window.opener.document.getElementById("proNumSelect").id="providerNumbers";
window.opener.document.getElementById("proFullnameSelect").id="providerFullnames";
fnParent();
}
})
}else{
alert("请先选一行数据!");
}
}

</script>


后台

//其他页面选择供应商资料的时候调用
publicStringselect(){
List<Provider>cusList=providerService.findByPager();
pager.setList(cusList);
returnSELECT;
}

//子页面选择供应商资料后执行的方法
publicvoidsetChileValue(){
StringproId=(String)this.getRequest().getParameter("proId");
ProviderselectProvider=providerService.get(proId);
Mapmap=newHashMap();
map.put("proId",proId);
map.put("proNumber",selectProvider.getNumber());
map.put("proFullname",selectProvider.getFullname());
try{
HttpServletResponseresponse=this.getResponse();
response.setContentType("text/plain;charset=UTF-8");
JSONArrayarray=JSONArray.fromObject(map);
response.getWriter().print(array);
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: