在当前页面选中打开新页面传值回到前页面

测试页面:
<html>
<head>
<title>测试</title>
<script>
function selectWin(index)
{
   if(index==1)
   {
      window.open("1.html");
   }
   else
   {
     window.open("2.html");
   }
}
</script>
</head>
<form name="myform">
<table>
<tr>
<td>选择</td>
<TD>
<INPUT type="checkbox" name="chk" value="1" onclick="selectWin(this.value)">选择一
<INPUT type="checkbox" name="chk" value="2" onclick="selectWin(this.value)">选择二
</TD>
<tr>
<tr>
<td>
<input type="text" name="txt1">
<input type="text" name="txt2">
</td></tr>
</table>
</form>
</html>



1.html
<html>
<head>
<title>测试</title>
<script>
function returnVal(index)
{
window.opener.document.forms[0].txt1.value=index;
window.close();

}
</script>
</head>
<form name="myform">
<table>
<td>
<input type="text" name="txt1">
<input type="button" value="返回" onClick="returnVal(document.forms[0].txt1.value);">
</td></tr>
</table>
</form>
</html>

2.html:

<html>
<head>
<title>测试</title>
<script>
function returnVal(index)
{
window.opener.document.forms[0].txt2.value=index;
window.close();
}
</script>
</head>
<form name="myform">
<table>
<td>
<input type="text" name="txt1">
<input type="button" value="返回" onClick="returnVal(document.forms[0].txt1.value);">
</td></tr>
</table>
</form>
</html>

猜你喜欢

转载自blog.csdn.net/qq_41330414/article/details/80908535