您的位置:首页 > Web前端 > JavaScript

模式窗体中调用父页面js与非模式化调用非父页面的js方法

2016-03-03 15:25 549 查看
最近项目中使用模式窗体,遇到以下问题记录一下:

模式窗体:你必须关闭该窗体,才能操作其它窗体;比如说,必须按确定或取消,或者按关闭。

非模式窗体:不必关闭该窗体,就可转换到其它窗体上进行操作。

一:非模式化窗体就是用


1.var val = parent.document.getElementById("txt1");
var val = parent.document.getElementById("txt1");


  

二:模式窗体

parent.html 

<html>
<head>
<script language="text/javascript">
function openwindow(){
//这个父页面通过 retval获取子页面的window.returnValue返回来的值
retval=window.showModalDialog("child.html")
Alert(retval);
document.getElementById('text1').value=retval
}

function Alert(msg){
alert(msg);
}
</script>
</head>
<body>
<form name=frm>
<input name=text1 type=text id="text1"/>
<input type=button onclick="javascript:openwindow()" value="Open window..">
</form>
</body>
</html>


  2. child.html

<html>
<head>
<script language="javascript">
function changeparent(){
//通过window.returnvalue把值返回父页面
window.returnValue="Value changed.."
window.close()
}
</script>
</head>
<body>
<form>
<input type=button onclick="javascript:changeparent()" value="Change main window’s textbox value..">
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: