我通过ShowModalDialog子窗体向父窗体传值,
父窗体:
function SelectControl(objname,objurl){
    var control = window.showModalDialog(objurl, null, "dialogWidth=400px; dialogHeight=300px; dialogLeft=" + (window.screen.width/2 - 200) +"; dialogTop=" + (window.screen.height/2 - 200) +"; help=yes; resizable=yes; status=yes; scroll=yes;");
    if(control != null){
        if($(objname) != null) $(objname).value = control;
    }
}
子窗体:
function ReturnAndClose(returnval){
    window.returnValue = returnval;
    window.close();
}
在IE下完美实现了,可在FF下,我发现,关闭子窗体时,子窗体正常传值给父窗体,父窗体也正常接收,不过父窗体马上就自动刷新,表单中的值都丢失了,为什么会这样呢?有什么解决办法么?

解决方案 »

  1.   

    index.jsp<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
    <head>
    <title>showModalDialog Pop1</title>
    <script>
    function pop2 () {
    window.showModalDialog('pop2.htm',window,'scroll:auto;center:yes;help:no;status:no;dialogWidth:200px;dialogHeight:200px');
    }
    </script>
    </head>
    <body>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <table align="center">
    <a href="javascript:pop2();">ShowModalDialog POP2</a>
    <br/>
    <input id="idTest" name="text" />
    <br/>
    <input id="idTest" name="text" value="3"/>
    <table>
    </body>
    </html>
      

  2.   

    index.htm<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
    <head>
    <title>showModalDialog Pop1</title>
    <script>
    function pop2 () {
    window.showModalDialog('pop2.htm',window,'scroll:auto;center:yes;help:no;status:no;dialogWidth:200px;dialogHeight:200px');
    }
    </script>
    </head>
    <body>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <table align="center">
    <a href="javascript:pop2();">ShowModalDialog POP2</a>
    <br/>
    <input id="idTest" name="text" />
    <br/>
    <input id="idTest" name="text" value="3"/>
    <table>
    </body>
    </html>
      

  3.   

    pop2.htm<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
    <head>
    <title>showModalDialog Pop2</title>
    <script>
    function returnValue(){
    var windowT = window.dialogArguments;
    windowT.document.getElementById('idTest').value = document.getElementById("idPop2").value;
    window.close();
    }
    function testSelect() {
    document.getElementById("comfirmImg").href = "javascript:returnValue()";

    </script>
    </head>
    <body>
    <br>
    <br>
    <table align="center">
    Name:<input type="text" id="idPop2" onblur="testSelect();">
    <p>
    <font color="red">Name is required !</font>
    </p>
    <a id="comfirmImg" href="#" style="cursor:default">ReturnValue</a>
    <table>
    </body>
    </html>
      

  4.   

    忘记说明了,我的子窗体页面是一个ASP.NET的WebForm,难道是因为这个原因?我试下
      

  5.   

    这是XTHML与HTML的差异性问题,XHTML文档,表单FORM内元素的行为,如Button的onclick,就会马上触发FORM的回传,真个网页也就刷新了,这种规范,IE8、FF、Chrome都是支持的。
    而回到HTML规范,FF、Chrome也同样会对Form内的元素行为进行响应而导致页面的刷新,但IE8不会。