模式对话框

一、实现功能:将子窗口中选中的值传入到父窗口中。

父窗口:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    function copen(){
        //打开了一个模式对话框 子窗口中用window.returnValue就把值传入到父窗口中。
        var city = window.showModalDialog("Demo5.html");
        document.getElementById("city").value=city;
    }
    function copen2(){
        window.open('Demo5.html');
    }
</script>
<input type="text" id="city"/><input type="button" value="打开子模式对话框" onclick="copen()"/>
</body>
</html>
子窗口:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
    <title>Title</title>
    <script type="text/javascript">
        //通过this来实现传对象,在函数中定义参数可以接收到对象。
        function retval(a){
            window.returnVal=a.value;
            window.close();
        }
    </script>
</head>
<body>
<input type="radio" name="city" value="北京" onclick="retval(this)"/>北京
<input type="radio" name="city" value="上海" onclick="retval(this)"/>上海
<input type="radio" name="city" value="长沙" onclick="retval(this)"/>长沙
<input type="radio" name="city" value="山东" onclick="retval(this)"/>山东
</body>
</html>

二、将父窗口中文本框的值写入到子窗口中。

父窗口:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    function copen2(){
        window.open('Demo7.html');
    }
</script>
<input type="text" id="city"/><input type="button" value="打开子窗口" onclick="copen2()"/>
</body>
</html>

子窗口:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
    <title>Title</title>
    <script type="text/javascript">
        function showParentData(){
            //1.得到打开这个窗口的窗口
            alert(window.opener.document.getElementById("city").value);
        }
    </script>
</head>
<body onload="showParentData()">
<input type="radio" name="city" value="北京" onclick="retval(this)"/>北京
<input type="radio" name="city" value="上海" onclick="retval(this)"/>上海
<input type="radio" name="city" value="长沙" onclick="retval(this)"/>长沙
<input type="radio" name="city" value="山东" onclick="retval(this)"/>山东
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值