Window.ShowModalDialog的传值问题

1.子页面向父页面传值

父窗体

<HTML>
<HEAD>
<script type="text/javascript">
        function execute() {  
           str =window.showModalDialog("modal1.htm",null,"dialogWidth=200px;dialogHeight=100px");
      alert(str);
        }  
    </script>
</head>
<BODY>  
    <input type="button" value="子窗体" onclick="execute()">
</BODY>
</html>

子窗体

<script>
      window.returnValue="http://homepage.yesky.com";
</script>

子窗体向父窗体传值比较简单,直接用window.returnValue传值即可.

2.父窗体向子窗体传值

父窗体

<script>
      var obj = new Object();
      obj.name="51js";
      window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
子窗体

<script>
      var obj = window.dialogArguments
      alert("您传递的参数为:" + obj.name)
</script>

父窗体向子窗体传值时,通过showModalDialog的第二个参数传值

 

你可能感兴趣的:(JavaScript,html)