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

父页面和模态子页面页面传值 以name遍历标签

2015-01-11 17:38 176 查看
 分为两个页面Father.aspx和module.aspx.分别是父页面和弹出的模态页面。

Father.aspx页面的关键代码为:

  var str = "";// 此变量为公共变量。为了接收子页面的值

  var win = window.showModalDialog('module.aspx', window, "resizable:no;scrollbars:no;status:no;help:no;dialogWidth:400px;dialogHeight:300px");

// 此语句为打开模态窗体。注意:第二个参数必须为window 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>测试模式对话框</title>

    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        var str = "";

        function tianjia() {

            var win = window.showModalDialog('module.aspx', window, "resizable:no;scrollbars:no;status:no;help:no;dialogWidth:400px;dialogHeight:300px");

        }

        function setValue() {

            document.getElementById("dates").value = str;

         }

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <label>

            弹出模式窗口</label>

        <input type="button" id="winMod" value="弹出模式窗口" onclick="tianjia()" />

        <input type="text" id="dates" />

    </div>

    </form>

</body>

</html>

模态页module

关键代码为:

  var txt;//记录返回值

  var main = window.dialogArguments;// 获得窗体参数

 main.str = checkeds;//获取返回值    str为父页面变量

            main.setValue();// 调用父页面的js方法  对变量值进行设置

            window.close();// 关闭模态窗口

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>

    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        var txt;

        var main = window.dialogArguments;

        function init() {

            var isSelected = "<%=items %>";

            var arrays = isSelected.split(',');

            var boxs = document.getElementsByName("1");

            for (var j = 0; j < arrays.length; j++) {

                for (var i = 0; i < boxs.length; i++) {

                    if (boxs.item(i).id == arrays[j]) {

                        boxs.item(i).checked = true;

                        break;

                    }

                }

            }

        }

        $(window).load(function () {

            init();

        });

        function checkSelect() {

            var checkeds = "";

            var arrCheckBox = document.getElementsByName("1");

            for (var i = 0; i < arrCheckBox.length; i++) {

                if (arrCheckBox.item(i).checked == true) {

                    checkeds += arrCheckBox.item(i).id + ",";

                }

            }

         //   alert(checkeds);

            main.str = checkeds;

            main.setValue();

            window.close();

        }

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <input type="button" id="sure" value="提交" onclick="checkSelect()" />

        <table style="width: 80%;">

            <tr>

                <th style="width: 33%;">

                    上午

                </th>

                <th style="width: 33%;">

                    中午

                </th>

                <th style="width: 33%;">

                    下午

                </th>

            </tr>

            <tr>

                <td>

                    <input id="11" name="1" type="checkbox" /> 

                </td>

                <td id="121">

                     <input id="12" name="1" type="checkbox" />

                </td>

                <td>

                     <input id="13" name="1" type="checkbox" />

                </td>

            </tr>

           

        </table>

    </div>

    </form>

    

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  js