1) 新页面式,通过使用window.open()
父页面parent.html
- <html>
- <head>
- <title>parent</title>
- <script language="javascript">
- function method() {
- window.open("child.html");
- }
- </script>
- </head>
- <body>
- <form method=post action="">
- <input type="text" name="" id="textparent"/><br>
- </form>
- <input type="button" value="foward" onclick="method()"/>
- </body>
- </html>
子界面child.html
- <html>
- <head>
- <title>child</title>
- <script language="JavaScript">
- function getValue(str) {
- window.opener.document.getElementById("textparent").value = str;
- window.close();
- }
- function load() {
- var str = window.opener.document.getElementById("textparent").value;
- window.document.getElementById("textchild").value = str;
- }
- </script>
- </head>
- <body onload="load()">
- <input type="text" name="" id="textchild" /><br>
- <a href="parent.html" onclick="getValue('11')">111</a>
- <a href="parent.html" onclick="getValue('22')">222</a>
- </body>
- </html>
点击父页面按钮跳转到新页面,也就是子页面,点击子页面的链接将值传递回父页面中,查看效果。
转载于:https://blog.51cto.com/sky2012/1065240