学习 学习 再学习

学习才是唯一的出路

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  31 随笔 :: 1 文章 :: 8 评论 :: 0 Trackbacks
window.showModalDialog(URL,dialogArgments.features) 打开一个新窗口

URL为要开启的网页名字。
dialogArgments为设定好传递给新视窗网页的参数,可以为任意数据类型。
feature 与open()的类似,都是格式方面的设定。调用格式为featureName1:featureValue1:(分号)featureName2:featureValue2:

关于feature具体的参数我就不详细写了,看名字就应该知道什么用处了吧。
certer , dialogHeight, dialogLeft,dialogTop,dialogWidth,help(是否显示help按钮,下同),status,resizeable
值=1为yes,0为no.

我认为最重要的是dialogArgments,可以传递值到新的窗口。
第二重要就是 它的返回值 window.returnValue.可以在showModalDialog开启的窗口关闭后前,回传一个任意类型的值。

dialogArgments  可以传入一个变量,但是 我认为最好是传入一个window 这样的话,不光你可以调用你前面定义的变量names 和a 等等,还可以取到前一个页面上任何元素的值.如下面的代码所示:

   <script language =javascript>
    alert(window.dialogArguments.names);
    alert(window.dialogArguments.a );
   
// alert(window.dialogArguments.document.form1.t1.value)
    window.dialogArguments.a = "Hello World";  //可以改变WebFromA里面的变量的值
    window.dialogArguments.document.form1.t1.value  = "t1";//可以修改WebFrom1里面的TextBox的value;
   
   

在WebFromB.aspx页面 我们可以取到 names 和a 的值还可以取到WebFromA的值.,还可以给它赋值.
整体的代码如下:
WebFromA.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormA.aspx.cs" Inherits="_5demo.ShowDig.WebFormA" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
    
<script language=javascript>
    
function fnA()
    
{
        names 
= new Array(3);
        names[
0= "chenzhifeng";
        names[
1= "chenjiang";
        
        a
= "shuhui";
     temp
=   window.showModalDialog("WebFormB.aspx",window);
       
// alert(a);
       document.getElementById("t3").value = temp;
    }

    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
<input type=text value ="feng" id = "t1" />
    
<br />
    
    
<input type=text value ="chen" id = "t2" />
    
<input type=button value = "Click Me" onclick ="fnA();" id = "btn1" />
    
<p>
    返回值:
<input type = "text" id= "t3" />
    
</div>
    
</form>
</body>
</html>

WebFormB.aspx 如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormB.aspx.cs" Inherits="_5demo.ShowDig.WebFormB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
    
<script language =javascript>
   
// alert(window.dialogArguments.names);
    alert(window.dialogArguments.a );
   
// alert(window.dialogArguments.document.form1.t1.value)
    window.dialogArguments.a = "Hello World";  //可以改变WebFromA里面的变量的值
    window.dialogArguments.document.form1.t1.value  = "t1";//可以修改WebFrom1里面的TextBox的value;
   
   
    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
<input type=text id = "tt" value = "Hello ZiFeng"/>
    
<script language =javascript>
    window.returnValue 
= document.getElementById("tt").value;
    window.close();
    
</script>
    
</div>
    
</form>
</body>
</html>

在WebFormB.aspx中 window.returnValue是用于 返回给WebFromA.aspx的值.
在WebFromA.aspx中,可以用一个变量来接收这个值 temp=   window.showModalDialog("WebFormB.aspx",window);

J-CN工作室
www.j-cn.org
posted on 2009-12-15 20:59 铁猴 阅读(19093) 评论(7)  编辑  收藏 所属分类: HTML相关

评论

# re: window.showModalDialog的传值和返回值 2013-12-17 09:44 飒飒是
飒飒  回复  更多评论
  

# re: window.showModalDialog的传值和返回值 [未登录] 2013-12-31 13:06 s
sss  回复  更多评论
  

# re: window.showModalDialog的传值和返回值 2014-09-24 14:46 10
101010  回复  更多评论
  

# re: window.showModalDialog的传值和返回值 2015-06-17 15:58 ertret
eee  回复  更多评论
  

# re: window.showModalDialog的传值和返回值 2015-06-17 15:58 ertret
eeee  回复  更多评论
  

# re: window.showModalDialog的传值和返回值 [未登录] 2015-10-30 11:25 test
如果传的值超长怎么传  回复  更多评论
  

# re: window.showModalDialog的传值和返回值 [未登录] 2016-04-14 14:56 77
777  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: