父页面
<script type="text/javascript">
//obj是父页面点击的控件 function openRecord(obj){ var url = "provider!select.do";//执行后台url var prop = '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"; $("#trSelect input[id='providerFullnames']").attr('id','proFullnameSelect'); $("#trSelect input[id='proId']").attr('id','proIdSelect'); var openWindows = window.open(url,window, prop); } </script>
子页面
<script type="text/javascript"> function fnParent(){ //window.opener.location.reload();//刷新父窗口 window.close(); } function onSelected(){ var proIds = document.getElementsByName("providerId"); var proId = ""; for(var i=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){ var proMap = 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>
后台
//其他页面选择供应商资料的时候调用 public String select(){ List<Provider> cusList = providerService.findByPager(); pager.setList(cusList); return SELECT; } //子页面选择供应商资料后执行的方法 public void setChileValue(){ String proId = (String)this.getRequest().getParameter("proId"); Provider selectProvider = providerService.get(proId); Map map = new HashMap(); map.put("proId", proId); map.put("proNumber", selectProvider.getNumber()); map.put("proFullname", selectProvider.getFullname()); try { HttpServletResponse response = this.getResponse(); response.setContentType("text/plain;charset=UTF-8"); JSONArray array = JSONArray.fromObject(map); response.getWriter().print(array); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }