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

首頁 > 編程 > JavaScript > 正文

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

2019-11-20 22:23:20
字體:
來源:轉載
供稿:網友
window.opener,是通過window.open打開子窗體的父窗體的引用。

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

子窗體完成輸入后,機構信息(id、name)自動填充到父窗體的orgId、orgName域
 
html代碼
復制代碼 代碼如下:

<tr>
<tdclass="tdEditLabel">機構</td>
<tdclass="tdEditContent" colspan="3"style="width:400px;text-align:left">
<input type="hidden"name="orgId" id="orgIdId">
<!-- 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域
 
html代碼
復制代碼 代碼如下:

<!--列表數據欄 -->
<c:iftest="${!empty pm.datas}">
<c:forEachitems="${pm.datas }" var="org">
<trbgcolor="#EFF3F7" class="TableBody1"onmouseover="this.bgColor = '#DEE7FF';"onmouseout="this.bgColor='#EFF3F7';">
<td align="center"vAlign="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();
}
}

選擇機構信息后的結果
 
完成機構信息(id、name)的輸入了,只是id在隱藏域中,看不到而已。
小結
說到對父窗體的引用,除了window.opener,就是window.parent了。window.opener是用于通過window.open方式打開子窗體,而window.parent是用于通過iframe方式打開子窗體。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 浑源县| 鞍山市| 芜湖市| 运城市| 五寨县| 清新县| 兰州市| 定南县| 宁德市| 兰溪市| 西林县| 商南县| 共和县| 淮南市| 宁晋县| 镇坪县| 庄浪县| 明水县| 姚安县| 瑞安市| 蚌埠市| 池州市| 汝州市| 四会市| 勐海县| 林州市| 漯河市| 扬中市| 福鼎市| 曲周县| 邢台县| 屯昌县| 大兴区| 南江县| 亳州市| 闽清县| 府谷县| 府谷县| 巫山县| 滨州市| 华容县|