http://www.bigant.cn/test/ui.htm为什么打开子窗体后,他的值不会累计上升父窗体
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
    <script language=javascript >
        function openwin(name)
        {
            var win = window.open("ui2.htm",name,"width=400,height=400") ;
            win.txt.value = win.txt.value + "\r\n" + name ;
            win.focus() ;
        }
    </script>
</head>
<body><input type="button" onclick="openwin('1')" value="win1"/>
<input type="button" onclick="openwin('2')" value="win2" />
</body>
</html>
子窗体<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<textarea id="txt" style="width:300px;height:300px;"></textarea>
 
</body>
</html>

解决方案 »

  1.   

    当你Open来子窗体时,没有加载完就去访问"txt"元素,会访问不到的,不推荐这些用法。
      

  2.   

    父窗体<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
        <script language=javascript >
            var wins = new Array();
            function getTalkWinIndex(talkerLoginName)
            {
                for(var i=0;i<wins.length;i++) 
                {
                    if (wins[i].name ==talkerLoginName)
                        return i ;
                }
                return -1 ;
            }
            
            function openwin(name)
            {
                var index = getTalkWinIndex(name) ;
                var win ;
    if (index == -1)
    {
        win = window.open("ui2.htm",name,"width=400,height=400") ; 
        wins[wins.length] = {name:name,win:win} ;
        win.onload = function(){
            win.document.getElementById("txt").value = win.document.getElementById("txt").value + name + "\r\n" ;
        }
    }
    else
    {
        if(wins[index].win  && wins[index].win.open  && !wins[index].win.closed) 
        {
              win = wins[index].win;
              win.document.getElementById("txt").value = win.document.getElementById("txt").value + name + "\r\n" ;
        }
        else
        {
            win = window.open("ui2.htm",name,"width=400,height=400") ; 
            wins[index].win = win ;
            win.onload = function(){
                win.document.getElementById("txt").value = win.document.getElementById("txt").value + name + "\r\n" ;
            }
        } }
                win.focus();
                
            }

        </script>
    </head>
    <body><input type="button" onclick="openwin('1')" value="win1"/>
    <input type="button" onclick="openwin('2')" value="win2" />
    </body>
    </html>子窗体<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    </head>
    <body>
    <textarea id="txt" style="width:300px;height:300px;"></textarea>
     
    </body>
    </html>
    <script></script>