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

首頁 > 編程 > JavaScript > 正文

JS父頁面與子頁面相互傳值方法

2019-11-20 20:59:47
字體:
來源:轉載
供稿:網友

一、子頁面是父頁面通過window.open彈出的情況
子頁面要向父頁面傳值,只要在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框架中的頁面情況

子頁面要向父頁面傳值,只要在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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉荫县| 手游| 阿克| 丽江市| 吴川市| 华亭县| 启东市| 克山县| 汽车| 雷波县| 松溪县| 昌都县| 唐海县| 襄垣县| 永兴县| 邵阳市| 石狮市| 上林县| 尉氏县| 宁远县| 齐齐哈尔市| 德安县| 阿鲁科尔沁旗| 定日县| 沭阳县| 河北省| 灵山县| 肃北| 四平市| 青海省| 汾西县| 周口市| 西青区| 米林县| 凤庆县| 武城县| 承德县| 沙坪坝区| 浪卡子县| 临沭县| 桂阳县|