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

最近项目中使用模式窗体,遇到以下问题记录一下:

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

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




一:非模式化窗体就是用
1.var val = parent.document.getElementById("txt1");   
var val = parent.document.getElementById("txt1");

  

二:模式窗体

  1. 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 οnclick="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 οnclick="javascript:changeparent()" value="Change main window’s textbox value..">
    </form>
    </body>
    </html>

转载于:https://www.cnblogs.com/panmy/p/5238784.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值