js中showModalDialog使用

案例一:

父窗口代码:

<input id="Button1" type="button" value="弹出窗口" onclick="return ShowCourse()" />

父窗口弹出子窗口代码

<script type="text/javascript">
        function ShowCourse() {
            var ret = window.showModalDialog("FieldCourse.aspx", window, 'dialogWidth:480px;dialogHeight:500px;dialogLeft:200px;dialogTop:150px;center:yes;help:no;resizable:no;status:no;scroll=no');
            if (ret != undefined) {
                document.getElementById("txtCourse").value = ret.value1;
                document.getElementById("hidCourse").value = ret.value2;
                return true;
            }
        }
    </script>

子窗口保存关闭代码

<script type="text/javascript">
        function SaveFieldSort() {
            var ret = new Object();
            ret.value1 = $("#hidField").val();
            ret.value2 = $("#hidSort").val();
            window.returnValue = ret;
            window.close();
            return false;
        }  
    </script>

案例二

<input id="Button1" type="button" value="弹出窗口" onclick="return ShowCourse()" />

父窗口弹出子窗口代码

<script type="text/javascript" language="javascript">
        function ShowDepart() {
            var ret = window.showModalDialog("FieldDepart.aspx", window, 'dialogWidth:180px;dialogHeight:360px;dialogLeft:200px;dialogTop:150px;center:yes;help:no;resizable:no;status:no;scroll=no');
            if (ret != undefined) {
                var obj = eval(ret);
                document.getElementById("txtDepart").value = obj[0].nodeName;
                document.getElementById("hidDepart").value = obj[0].nodeId;
                return false;
            }
        }
    </script>

子窗口保存关闭代码

<script type="text/javascript">
        function selectNode() {
            var returnValue = "";
            returnValue = "[{nodeId:'aaa',nodeName:'bbb'}]";
            window.returnValue = returnValue;
            window.close();
            return false;
        }
    </script>

你可能感兴趣的:(showModalDialog)