• 用showModalDialog写的简单弹出框传参与反参


    vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])

    sURL -- 必选参数,类型:字符串。用来指定对话框要显示的文档的 URL
    vArguments -- 可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括 数组等。对话框通过window.dialogArguments来取得传递进来的参数。
    sFeatures -- 可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。

    sFeatures 可选参数有:

    dialogHeight:sHeight 可选字符串,指定对话框窗口的修饰,使用与一个或多个值以下分号分隔: [1]
    dialogHeight:sHeight
    设置对话框窗口的高度(见备注默认度量单位)。
    dialogLeft: sXPos
    设置对话框窗口相对于 桌面左上角的左侧位置。
    dialogTop:sYPos
    设置对话框窗口相对于 桌面左上角的榜首位置。
    dialogWidth:sWidth
    设置对话框窗口的宽度(见备注默认度量单位)。
    center:{ yes | no | 1 | 0 | on | off }
    中心指定是否要在 桌面对话窗口。.默认为 yes。
    dialogHide:{ yes | no | 1 | 0 | on | off }
    指定 对话框窗口是否隐藏在打印或使用 打印预览。此功能只有当一个对话框是从信任的 应用程序打开。默认是no。
    edge:{ sunken | raised }
    指定对话框窗口边缘风格。 默认是raised 。
    resizable:{ yes | no | 1 | 0 | on | off }
    指定对话框窗口中是否有固定的尺寸。 默认是no。
    scroll:{ yes | no | 1 | 0 | on | off }
    指定对话框窗口是否显示滚动条。默认为 yes。
    status:{ yes | no | 1 | 0 | on | off }
    指定对话框窗口是否显示状态栏。默认为yes不受信任的对话窗口和窗口 信任的对话。
    unadorned:{ yes | no | 1 | 0 | on | off }
    指定对话框窗口是否显示边框的窗口 浏览器。 此功能只有当一个对话框是从信任的 应用程序打开。默认是no。
    minimize:{ yes | no}
    指定对话框是否显示最小化按钮,默认不显示
    maximize:{ yes | no}
    指定对话框是否显示最大化按钮,默认不显示
    以上信息来自百度百科。

    具体使用如下:

    主页:index.html

    <html>
     <head>
      <title> 弹出框小例子 </title>
      <script>
    	function showWinPassArr(){
    		var arr=['test1','19','famle'];//构造参数-数组传递给子窗口
    		var str =showModalDialog('children.html',arr,'dialogWidth=280px;dialogHeight=200px;title=测试弹出框');//定义变量str接收返回值。
    		alert(str[0]+str[1]);//弹出返回值
    	}
    	function showWinPassObj(){
    		var obj={name:'test1',age:19,sex:'famle'};//构造参数-对象传递给子窗口
    		showModalDialog('children2.html',obj,'dialogWidth=280px;dialogHeight=200px');
    	}
    	function showOpenWin(){
    		window.open("http://www.kao.com/","Window Name",
    		"menubar=no,location=no,resizable=no,scrollbars=no,status=no");
    	}
      </script>
     </head>
    
     <body>
      <input type="button" value="弹出模态窗口-传递数组参数" onclick="showWinPassArr();"/>
      <input type="button" value="弹出模态窗口-传递对象参数" onclick="showWinPassObj();"/>
      <input type="button" value="winOpen" onclick="showOpenWin();"/>
     </body>
    </html>
    

    弹出框子页面children.html

    <html>
     <head>
      <title>接收传递参数为数组</title>
     </head>
    <script>
    	var arr = window.dialogArguments;//接收参数
    	alert("name:"+arr[0]+" age:"+arr[1]+" sex:"+arr[2]);
    	var rtnarr=['这个是从子窗口返回的参数','1234567'];//构造返参
    	window.returnValue=rtnarr;//回传参数
    </script>
     <body>
     <center> children.html</center>
     </body>
    </html>
    


    弹出框子页面children2.html

    <html>
     <head>
      <title>接收传递参数为对象</title>
     </head>
     <script>
    	var obj = window.dialogArguments;
    	alert(obj.age);
     </script>
     <body>
      children2.html
     </body>
    </html>
    


  • 相关阅读:
    (十)jQuery对表单、表格的操作
    (九)jQuery中的动画(载)
    (八)jQuery中的事件
    (七)jQuery中的DOM操作
    (六)jQuery选择器
    (五)解决jQuery和其它库的冲突
    (四)DOM对象和jQuery对象
    (三)初识jQuery
    (二)关于jQuery
    (一)关于jQuery的网上资源
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3328993.html
Copyright © 2020-2023  润新知