国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

window.opener用法和用途實例介紹

2024-05-06 15:50:46
字體:
來源:轉載
供稿:網友
window.opener,是通過window.open打開子窗體的父窗體的引用,下面為大家詳細介紹下其具體的使用方法,感興趣的朋友可以參考下

window.opener,是通過window.open打開子窗體的父窗體的引用。

比如在父窗體parentForm里面,通過window.open("subForm.html"),那么在subform.html中window.opener就代表parentForm。既然在子窗體中能夠拿到父窗體的引用,那么就可以在子窗體中設置父窗體的字段值或者調用js方法。
實例:添加人員信息時,其中的機構信息通過子窗體完成輸入
父親窗體,用于添加人員信息。

子窗體完成輸入后,機構信息(id、name)自動填充到父窗體的orgId、orgName域

window.opener用法和用途實例介紹

 
html代碼

復制代碼 代碼如下:


<tr>
<tdclass="tdEditLabel">機構</td>
<tdclass="tdEditContent" colspan="3"style="width:400px;text-align:left">
<input type="hidden"name="orgId">
<!-- disabled修飾的內容 不提交 -->
<input type="text"name="orgName" disabled="disabled"id="orgNameId">
<input type="button"name="selectOrgButton" value="選擇機構"
onclick="openWin('org.do?select=true','selectorg',800,500,1)">
</td>
</tr>


JS代碼

復制代碼 代碼如下:


/*
*打開新窗口(通過window.open())
* f:鏈接地址
* n:窗口的名稱
* w:窗口的寬度
* h:窗口的高度
* s:窗口是否有滾動條,1:有滾動條;0:沒有滾動條
*/
functionopenWin(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();
returnopenwin;
}


子窗體,供選擇機構信息。

當選擇后(通過單擊radio),機構信息(id、name)將填充到父窗體的orgId、orgName域

window.opener用法和用途實例介紹

 
html代碼

復制代碼 代碼如下:


<!--列表數據欄 -->
<c:iftest="${!empty pm.datas}">
<c:forEachitems="${pm.datas }" var="org">
<trbgcolor="#EFF3F7"onmouseover="this.bgColor = '#DEE7FF';"onmouseout="this.bgColor='#EFF3F7';">
<tdvAlign="center">
<input type="radio"onclick="selectOrg('${org.id }','${org.name }')">
</td>
<tdalign="center" vAlign="center">${org.id}</td>
<tdalign="center" vAlign="center"><ahref="org.do?parentId=${org.id }&select=true">${org.name}</a></td>
<tdalign="center" vAlign="center">${org.sn }</td>
<tdalign="center" vAlign="center">${org.parent.name}</td>
</tr>
</c:forEach>
</c:if>


JS代碼

復制代碼 代碼如下:


functionselectOrg(id,name){
if(window.opener){
window.opener.document.all.orgIdId.value= id;
window.opener.document.all.orgNameId.value= name;
window.close();
}
}


選擇機構信息后的結果

window.opener用法和用途實例介紹

 
完成機構信息(id、name)的輸入了,只是id在隱藏域中,看不到而已。
小結
說到對父窗體的引用,除了window.opener,就是window.parent了。window.opener是用于通過window.open方式打開子窗體,而window.parent是用于通過iframe方式打開子窗體。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 台安县| 临桂县| 阿合奇县| 兴山县| 买车| 忻城县| 游戏| 广东省| 将乐县| 闽清县| 达州市| 遂川县| 延吉市| 原阳县| 白城市| 东兴市| 和龙市| 石棉县| 东港市| 商河县| 岚皋县| 黑龙江省| 遂平县| 石林| 巩义市| 琼结县| 孟津县| 监利县| 城固县| 姚安县| 永宁县| 简阳市| 大悟县| 洞头县| 阿拉善左旗| 龙泉市| 德昌县| 林甸县| 汨罗市| 和田县| 淮北市|