JS父頁面與子頁面相互傳值方法
一、子頁面是父頁面通過window.open彈出的情況
子頁面要向父頁面?zhèn)髦?,只要在document前面加window.opener即可。
如:
1.父頁面代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔title>
head>
<script language="javascript">
function tanchu()
{
window.open("Untitled-5.html");
}
script>
<body>
<form id="form1" name="form1" method="post" action="">
<label> <input type="submit" name="button" id="button" value="提交"
onclick="tanchu()" />
label> <label> <input type="text" name="textfield" id="textfield" />
label>
form>
</body>
</html>
2.子頁面代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔title>
head>
<script language="javascript">
function aaa()
{
window.opener.document.getElementByIdx('textfield').value='123123123';
}
script>
<body>
<form id="form1" name="form1" method="post" action="">
<label> <input type="submit" name="button" id="button" value="提交"
onclick="aaa()" />
label>
form>
</body>
</html>
二、子頁面是iframe框架中的頁面情況
子頁面要向父頁面?zhèn)髦?,只要在document前面加parent即可。
1.父頁面代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔title>
head>
<body>
<form id="form1" name="form1" method="post" action="">
<label> <input type="text" name="textfield" id="textfield" />
label>
<iframe id="myiframe" src="Untitled-3.html">iframe>
form>
</body>
</html>
2.子頁面代碼
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔title>
head>
<script language="javascript">
function aa()
{
var a=parent.document.getElementByIdx('textfield').value;
alert(a);
}
script>
<body>
<form id="form1" name="form1" method="post" action="">
<label> <input type="submit" name="button" id="button" value="提交"
onClick="aa()" />
label>
form>
</body>
</html>
相關(guān)文章
JavaScript代碼實現(xiàn)圖片循環(huán)滾動效果
這篇文章主要介紹了JavaScript代碼實現(xiàn)圖片循環(huán)滾動效果的相關(guān)資料,非常不錯,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2016-06-06JavaScript和jQuery獲取input框的絕對位置實現(xiàn)方法
下面小編就為大家?guī)硪黄狫avaScript和jQuery獲取input框的絕對位置實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10html中通過JS獲取JSON數(shù)據(jù)并加載的方法
本篇內(nèi)容主要給大家講了如何通過javascript解析JSON并得到數(shù)據(jù)后添加到HTML中的方法,需要的朋友參考下。2017-11-11uniapp與webview之間的相互傳值的實現(xiàn)
這篇文章主要介紹了uniapp與webview之間的相互傳值的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06