日期:2014-05-16  浏览次数:20511 次

JSP以Window形式打开把值从子窗体传回给父窗体 用jquery
首先在父窗体(JSP)引用
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
下面这个是页面跳转的JS
<code>
function chooseCustomer(){
  var url= "${ctx}/objection.do?method=chooseCustomer";    //转向网页的地址的Action;
  var name="选择客户信息";                           //网页名称,可为空;
  var iWidth=950;                          //弹出窗口的宽度;
  var iHeight=650;        //弹出窗口的高度;
  var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
  window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=no,resizeable=no,location=no,status=no');
}
</code>
下面一个JS是从子窗体里调用的回调函数
<code>
  //选择客户的回调函数
function chooseUserCallBack(productid,productname){
$("#CCustomerId").attr("value",productid);  //CCustomerId 文体框的ID
$("#fourSName").attr("value",productname);
}
如:
<td width="10%" class="odd">
客户名称:
</td>
<td>
<input type="text" name="CCustomerName" id="CCustomerName" width="18%" />
</td>
</code>
好,下面我们来看下子窗体。子窗体是通过Action返回的页面
  在子窗体的前面定义JS
<code>
  <script type="text/javascript">
         var openerWindow = window.opener;
var CGoodsStrengthId = "";
var CGoodsStrengthName = "";

function sele(id,name){
CGoodsStrengthId = id;
CGoodsStrengthName = name;
}
function checkFather(){
if(null==CGoodsStrengthId || CGoodsStrengthId==""){
alert("请先选择后再提交。");
return;
}
window.openerWindow.chooseUserCallBack(CGoodsStrengthId,CGoodsStrengthName);
window.close();

}
  </script>
</code>
在单选按扭上调用sele();JS
提交的时候调用
<input onclick="checkFather();" value=" 提  交 " type="button" />
就可以了。