我通过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下,我发现,关闭子窗体时,子窗体正常传值给父窗体,父窗体也正常接收,不过父窗体马上就自动刷新,表单中的值都丢失了,为什么会这样呢?有什么解决办法么?
父窗体:
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下,我发现,关闭子窗体时,子窗体正常传值给父窗体,父窗体也正常接收,不过父窗体马上就自动刷新,表单中的值都丢失了,为什么会这样呢?有什么解决办法么?
<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>
<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>
<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>
而回到HTML规范,FF、Chrome也同样会对Form内的元素行为进行响应而导致页面的刷新,但IE8不会。