无法将javascript函数/变量从一个案例传递到另一个案例

时间:2013-10-15 15:52:42

标签: javascript php html function parent-child

我试图让父窗口在一个案例中打开一个子窗口,然后在父窗口中以不同的方式关闭该窗口:

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

javascripts.js:

var myWindowwin;

function openWin() {
    myWindowwin = window.open("path/file.html","name","width=547,height=480");
}

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

子窗口将打开,但不会关闭。

0 个答案:

没有答案