0

我试图在父窗口进入 switch 和 case 语句内的不同情况时打开一个子弹出窗口,然后在父窗口进入另一个不同情况时关闭该子窗口:

case "1": 
    $nextDecision = "
        <form action=\"index.php\" method=\"get\">
          <input type=\"radio\" name=\"choice\" value=\"val1\">message<br>
          <input type=\"submit\">
        </form>";
    ?>
    <script language="JavaScript" type="text/javascript" src="javascripts.js"></script>
    <body onload="javascript:openWin()"></body>
    <?php
    break;
case "2": 
    $nextDecision = "
        <form action=\"index.php\" method=\"get\">
               <input type=\"radio\" name=\"choice\" value=\"val2\">message<br>
           <input type=\"submit\">
        </form>";
    ?>
    <body onload="javascript:closeWin()"></body>
    <?php
    break;

javascripts.js:

function openWin() {
   myWindow=window.open("file/popup.html", "name", "width=200, height=100");
}
function closeWin() {
   myWindow.close();
}
4

1 回答 1

0

您试图在身体负载时关闭子窗口,它无权访问子窗口。尝试在父窗口重新加载之前关闭它..

function closeWin() {
   document.getElementById('choice').value='val2';
   myWindow.close();
 }

<form action=\"index.php\" method=\"get\">
   <input type=\"radio\" id=\"choice\" name=\"choice\" onsubmit="closeWin()" value=\"val2\">message<br>
   <input type=\"submit\" >
</form>";
于 2013-10-15T02:01:32.930 回答