码迷,mamicode.com
首页 > 其他好文 > 详细

前台主页面给子页面赋值(回调)

时间:2015-06-05 15:38:13      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

1、主页面

<html>
<body>
<script type="text/javascript">
    var _callback;
    function exec(callback) {
        _callback = callback;
        document.getElementById("txtResult").value = (new Date()).toLocaleString();
    }

    function subpage() {
        if (_callback) {
            try {
                _callback("我要给子页面赋值123");
            } catch (e) {
            }
        }
    }
</script>
<input type="button" value="打开窗口" onclick="window.open(‘children.htm‘)" />
<input type="button" value="回传" onclick="subpage()" />
<input type="text" id="txtResult" />
</body>
</html>

2、子页面

<html>
<body>
<script type="text/javascript">
    function toppage() {
        opener.exec(exec1);
    }

    function exec1(msg) {
        document.getElementById("txtResult").value = msg;
    }
</script>
<input type="button" value="主页面方法" onclick="toppage()" />
<input type="text" id="txtResult" />
</body>
</html>

 

前台主页面给子页面赋值(回调)

标签:

原文地址:http://www.cnblogs.com/honghong75042/p/4554568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!