利用Javascript从子窗口设置父窗口的值在Hibernate的一对多数据列表中经常包含这样一个需求:例如在我们添
利用Javascript从子窗口设置父窗口的值
在Hibernate的一对多数据列表中经常包含这样一个需求:例如在我们添加人员的时候需要选择新添加的这个人属于那一个组,这就要显示组的信息在这里可以用下拉框实现,但是更好的实现是弹出一个新的窗口在新弹出的窗口中显示所有的组然后进行选择!
//添加页面
<tr><td >所属组</td><td id="orgName" disabled="disabled"><input type="hidden" name="orgId" id="orgId"><input type="button" value="选择" onclick="openWin('person!selectOrg.action','selectparties',800,600,1);"></td><td >姓名</td><td name="name"></td></tr>//openWin函数
function openWin(f,n,w,h,s){sb = s == "1" ? "1" : "0";l = (screen.width - w)/2;t = (screen.height - h)/2;sFeatures = "left="+ l +",top="+ t +",height="+ h +",width="+ w+ ",center=1,scrollbars=" + sb + ",status=0,directories=0,channelmode=0";openwin = window.open(f , n , sFeatures );if (!openwin.opener)openwin.opener = self;openwin.focus();}//调用函数的时候弹出一个新的窗口把所有的组显示出来
设置父窗口的函数:
function selectOrg(orgId,orgName){window.opener.document.getElementById("orgName").value = orgName;window.opener.document.getElementById("orgId").value = orgId;window.close();}//调用页面的函数实现选择 <td align="center" vAlign="middle"> <input type="radio" id="selectOrgId" onclick="selectOrg('<s:property value="id"/>','<s:property value="orgName"/>');" /> </td>最终的页面效果:
