• JavaScript--Window.open(获取子窗口返回值)


    实现案列:在A页面点击按钮,弹框进入B页面,点击B页面下拉框,关闭窗体,并将选中的值返回到A页面!

    A页面代码:

    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script src="js/jquery-1.10.2.min.js"></script>
            <script>
                function openWin() {
                    var name; //网页名称,可为空;
                    var iWidth = "800"; //弹出窗口的宽度;
                    var iHeight = "800"; //弹出窗口的高度;
                    var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
                    var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
                    var win = window.open("B.html", name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth +
                        ',innerWidth=' +
                        iWidth + ',top=' + iTop + ',left=' + iLeft +
                        ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
                    
                }
                function sele(NO) {
                    //NO为返回值
                    $("#txtName").val(NO);
                }
            </script>
        </head>
        <body>
            <input type="text" id="txtName" onclick="openWin()"/>
        </body>
    </html>

    B页面代码:

    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script src="js/jquery-1.10.2.min.js"></script>
            <script>
                function getvalue(v) {
                    window.opener.sele(v);
                    window.close();
                }
            </script>
        </head>
        <body>
            <select id="test" onchange="getvalue(this.options[this.options.selectedIndex].value)">
                <option value="1">文本1</option>
                <option value="2">文本2</option>
                <option value="3">文本3</option>
                <option value="4">文本4</option>
                <option value="5">文本5</option>
            </select>
        </body>
    </html>

    完美解决!

  • 相关阅读:
    索引压缩
    拼写校正
    词典(词汇表)
    Text Relatives II
    Text Relatives
    CoreText
    Quartz2D Text
    PDF Document Creation, Viewing
    Core Graphics Layer Drawing
    Bitmap Images and Image Masks
  • 原文地址:https://www.cnblogs.com/dcy521/p/11268031.html
Copyright © 2020-2023  润新知