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


    父页面
    <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();
            }
        }
     
  • 相关阅读:
    hdoj 5461 Largest Point
    poj 2186 Popular Cows【tarjan求scc个数&&缩点】【求一个图中可以到达其余所有任意点的点的个数】
    [LC] 64. Minimum Path Sum
    [LC] 122. Best Time to Buy and Sell Stock II
    [LC] 121. Best Time to Buy and Sell Stock
    [LC] 91. Decode Ways
    [LC] 62. Unique Paths
    [LC] 674. Longest Continuous Increasing Subsequence
    [LC] 300. Longest Increasing Subsequence
    [LC] 746. Min Cost Climbing Stairs
  • 原文地址:https://www.cnblogs.com/kisstear/p/5416674.html
Copyright © 2020-2023  润新知