在主頁面點擊按鈕,彈出一個模式窗口,輸入值后,點擊完成按鈕,父頁面的某個textbox可以根據模式窗口的值改變而改變。
怎麽實現?
謝謝。

解决方案 »

  1.   

    a.htm
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    function setValue(){
    var ret = window.showModalDialog("b.htm",'','');
    document.getElementById("txt1").value=ret;
    }
    </script>
    </head><body>
    <input type=text value="" id=txt1 readonly>
    <input type=button onclick=setValue() value="set value">
    </body></html>b.htm
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>b</title>
    <script>
    function on_submit(){
    window.returnValue=document.getElementById("txt2").value;
    window.close();
    }
    </script>
    </head><body>
    <input type="text" value="" id="txt2">
    <input type=button value=submit onclick="on_submit()">
    </body></html>
      

  2.   

    模式或非模式都可用
    index.html <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    function openPage(page){
    var arg = {
    window: window,
    input: document.getElementById('input')
    };
    //window.showModelessDialog(page, arg, 'status:no;edge:sunken;dialogWidth:600px;dialogHeight:350px');
    window.showModalDialog(page, arg, 'status:no;edge:sunken;dialogWidth:600px;dialogHeight:350px');
    }
    </script>
    </head>
    <body>
    <a hre="#" onclick="openPage('input.html');" style="cursor:hand">open</a>
    <textarea id="input"></textarea>
    </body>
    </html>input.html <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    var arg = window.dialogArguments;
    window.onload =function(){
    var done = document.getElementById('done'),
    input = document.getElementById('input');
    done.onclick = function(){
    arg.input.value = input.value;
    }
    }
    </script>
    </head>
    <body>
    <textarea id="input"></textarea>
    <input type="button" id="done" value="done" />
    </body>
    </html>
      

  3.   

    1L 正解   lz在子页面也可以获得父窗口传过来的值   showModalDialog()的第二个参数就是父窗口传向子窗口的值
    在字窗口使用 dialogArgument接收这个值
      

  4.   

    首先謝謝各位。一個值返回沒有問題了。那如果是要從子窗口獲取多個值,怎麽辦?
    用window.returnValue獲取字符串數組嗎?
      

  5.   

    一样的道理,直接向window.returnValue赋值就行了
    a.htm
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    function setValue(){
    var ret = window.showModalDialog("b.htm",'','');
    document.getElementById("txt1").value=ret[0];
    }
    </script>
    </head><body>
    <input type=text value="" id=txt1 readonly>
    <input type=button onclick=setValue() value="set value">
    </body></html>b.htm
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>b</title>
    <script>
    function on_submit(){
    window.returnValue=[document.getElementById("txt2").value,document.getElementById("txt3").value,document.getElementById("txt4").value];
    window.close();
    }
    </script>
    </head><body>
    <input type="text" value="" id="txt2">
    <input type="text" value="" id="txt3">
    <input type="text" value="" id="txt4">
    <input type=button value=submit onclick="on_submit()">
    </body></html>
      

  6.   

    謝謝lihui_shine ,真厲害。