码迷,mamicode.com
首页 > 其他好文 > 详细

模态窗口和非模态窗口

时间:2014-12-18 01:28:02      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ar   io   color   os   使用   sp   

对话框一般分为两种类型:模态类型(modal)与非模态类型(modeless)。所谓模态对话框,就是指除非采取有效的关闭手段,用户的鼠标焦点或者输入光标将一直停留在其上的对话框。非模态对话框则不会强制此种特性,用户可以在当前对话框以及其他窗口间进行切换。本文介绍如何使用JavaScript语言来创建这两种类型的对话框、控制其大小和位置、改变其外观以及在对话框间的数据传递。(引用) 
一、创建模态和非模态对话框

创建模态对话框:(会缓存最近一次页面的值,通过一些设置可绕过系统的判断) 
vReturnValue = window.showModalDialog(sURL [, vFreeArgument] [, sOrnaments]); 
创建非模态对话框:(不会) 
vReturnValue = window.showModelessDialog(sURL [, vFreeArgument] [, sOrnaments]);

· VReturnValue:对于showModalDialog(),它表示被打开的对话框窗口设置的returnValue属性值。对于showModelessDialog(),它表示新窗口对象。  
· VFreeArgument:这个参数可用于传递某种类型的数据到打开的对话框,数据可以是一个数值、字符串、数组或者一个对象类型。在新窗口中引用这个数值时,可通过新创建window对象的dialogArguments 属性。  
· SOrnaments:用这个参数指定新窗口的外观。可选择的窗口属性有很多种,当有多种控制需求时,将相关内容用一个字符串连接起来,其间用分号隔开。以下是可选择的属性种类:  
o dialogHeight: sHeight  
o dialogLeft: sXpos  
o dialogTop: sYpos  
o dialogWidth: sWidth  
o center: ( yes | no | 1 | 0 | on | off )  
o dialogHide: ( yes | no | 1 | 0 | on | off )  
o edge: ( sunken | raised )  
o help: ( yes | no | 1 | 0 | on | off )  
o resizable: ( yes | no | 1 | 0 | on | off )  
o scroll: ( yes | no | 1 | 0 | on | off )  
o status: ( yes | no | 1 | 0 | on | off )  

二、控制对话框大小和位置

三、改变对话框外观
 
四、从Noname1.html页面传递数据到Noname2.html页面

传递对象类型数据 

bubuko.com,布布扣<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
bubuko.com,布布扣<HTML>
bubuko.com,布布扣<HEAD>
bubuko.com,布布扣<TITLE>模态窗口和非模态窗口</TITLE>
bubuko.com,布布扣<script language="javascript">
bubuko.com,布布扣 var sColor="yyyy";
bubuko.com,布布扣 var sName="xmddl369";
bubuko.com,布布扣 function showModalWindow(){
bubuko.com,布布扣   window.showModalDialog(‘Noname2.html‘,window,‘dialogWidth:400px;dialogHeight:400px‘);
bubuko.com,布布扣 }
bubuko.com,布布扣 function showModellessWindow(){
bubuko.com,布布扣  window.showModelessDialog(‘Noname2.html‘,window,‘dialogWidth:400px;dialogHeight:400px;edge:sunken‘);
bubuko.com,布布扣 }
bubuko.com,布布扣 function update() 
bubuko.com,布布扣 
bubuko.com,布布扣  oColor.innerText = sColor; 
bubuko.com,布布扣 } 
bubuko.com,布布扣 document.write("sColor="+sColor+"<br>");
bubuko.com,布布扣 document.write("sName="+sName+"<br>");
bubuko.com,布布扣</script>
bubuko.com,布布扣</HEAD>
bubuko.com,布布扣
bubuko.com,布布扣<BODY>
bubuko.com,布布扣<form>
bubuko.com,布布扣<input type="button" name="button" value="打开一个模态窗口" onclick="showModalWindow()">
bubuko.com,布布扣<input type="button" name="button" value="打开一个非模态窗口" onclick="showModellessWindow()">
bubuko.com,布布扣<BR>
bubuko.com,布布扣<P>输入你最喜欢的颜色: <SPAN ID="oColor" STYLE="color:red;font-size:24">Yellow</SPAN></P>
bubuko.com,布布扣</form>
bubuko.com,布布扣</BODY>
bubuko.com,布布扣</HTML>
bubuko.com,布布扣-------------------
bubuko.com,布布扣
bubuko.com,布布扣<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
bubuko.com,布布扣<HTML>
bubuko.com,布布扣<HEAD>
bubuko.com,布布扣<TITLE> New Document </TITLE>
bubuko.com,布布扣<script language="javascript">
bubuko.com,布布扣function getInfoAndUpdate() {
bubuko.com,布布扣 var callerWindowObj = dialogArguments; //得到文档的引用
bubuko.com,布布扣 callerWindowObj.sColor = document.all("oEnterColor").value; 
bubuko.com,布布扣 callerWindowObj.update(); 
bubuko.com,布布扣 }
bubuko.com,布布扣function cancel() 
bubuko.com,布布扣 var callerWindowObj = dialogArguments; 
bubuko.com,布布扣 callerWindowObj.sColor = "Yellow"; 
bubuko.com,布布扣 callerWindowObj.update();  
bubuko.com,布布扣
bubuko.com,布布扣</script>
bubuko.com,布布扣</HEAD>
bubuko.com,布布扣<BODY>
bubuko.com,布布扣<form>
bubuko.com,布布扣输入你最喜欢的颜色:<INPUT type="text" name="oEnterColor" ID="oEnterColor"><BR><BR> 
bubuko.com,布布扣<INPUT VALUE="Apply" TYPE=button onclick="getInfoAndUpdate();"> 
bubuko.com,布布扣<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();"> 
bubuko.com,布布扣<INPUT VALUE="Cancel" TYPE=button onclick="cancel();window.close();"> 
bubuko.com,布布扣
bubuko.com,布布扣</form>
bubuko.com,布布扣</BODY>
bubuko.com,布布扣</HTML>

传递数组引用类型数据 

bubuko.com,布布扣<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
bubuko.com,布布扣<HTML>
bubuko.com,布布扣<HEAD>
bubuko.com,布布扣<TITLE>模态窗口和非模态窗口</TITLE>
bubuko.com,布布扣<script language="javascript">
bubuko.com,布布扣 var fruit=new Array();
bubuko.com,布布扣 fruit[0]="苹果";
bubuko.com,布布扣 fruit[1]="桔子";
bubuko.com,布布扣 fruit[2]="梨";
bubuko.com,布布扣 fruit[3]="香蕉";
bubuko.com,布布扣 function showModalWindow(){
bubuko.com,布布扣   window.showModalDialog(‘Noname2.html‘,fruit,‘dialogWidth:400px;dialogHeight:400px‘);
bubuko.com,布布扣 }
bubuko.com,布布扣 function showModellessWindow(){
bubuko.com,布布扣  window.showModelessDialog(‘Noname2.html‘,fruit,‘dialogWidth:400px;dialogHeight:400px;edge:sunken‘);
bubuko.com,布布扣 }
bubuko.com,布布扣</script>
bubuko.com,布布扣</HEAD>
bubuko.com,布布扣
bubuko.com,布布扣<BODY>
bubuko.com,布布扣<form>
bubuko.com,布布扣<input type="button" name="button" value="打开一个模态窗口" onclick="showModalWindow()">
bubuko.com,布布扣<input type="button" name="button" value="打开一个非模态窗口" onclick="showModellessWindow()">
bubuko.com,布布扣<BR>
bubuko.com,布布扣</form>
bubuko.com,布布扣</BODY>
bubuko.com,布布扣</HTML>
bubuko.com,布布扣
bubuko.com,布布扣------------------
bubuko.com,布布扣
bubuko.com,布布扣<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
bubuko.com,布布扣<HTML>
bubuko.com,布布扣<HEAD>
bubuko.com,布布扣<TITLE> New Document </TITLE>
bubuko.com,布布扣<SCRIPT LANGUAGE="JScript">
bubuko.com,布布扣function deWrite(){
bubuko.com,布布扣 var myobject=document.getElementById("ifruit");
bubuko.com,布布扣 var myfruit=dialogArguments;
bubuko.com,布布扣
bubuko.com,布布扣 for(count=0;count<myfruit.length;count++){
bubuko.com,布布扣  var oOption = document.createElement("OPTION");
bubuko.com,布布扣  oOption.text=myfruit[count];
bubuko.com,布布扣  oOption.value=/count;
bubuko.com,布布扣  myobject.add(oOption);
bubuko.com,布布扣 }
bubuko.com,布布扣}
bubuko.com,布布扣</SCRIPT>
bubuko.com,布布扣</HEAD>
bubuko.com,布布扣<BODY>
bubuko.com,布布扣<form>
bubuko.com,布布扣<input type="button" name="button" value="click me" onclick="deWrite()">
bubuko.com,布布扣<br>增加水果:
bubuko.com,布布扣<SELECT ID="ifruit" NAME="ifruit">
bubuko.com,布布扣</SELECT>
bubuko.com,布布扣</form>
bubuko.com,布布扣</BODY>
bubuko.com,布布扣</HTML>

传递值类型数据

bubuko.com,布布扣<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
bubuko.com,布布扣<HTML>
bubuko.com,布布扣<HEAD>
bubuko.com,布布扣<TITLE>模态窗口和非模态窗口</TITLE>
bubuko.com,布布扣<script language="javascript">
bubuko.com,布布扣 function showModalWindow(){
bubuko.com,布布扣   window.showModalDialog(‘Noname2.html‘,"xmddl",‘dialogWidth:400px;dialogHeight:400px‘);
bubuko.com,布布扣 }
bubuko.com,布布扣 function showModellessWindow(){
bubuko.com,布布扣  window.showModelessDialog(‘Noname2.html‘,"xmddl369",‘dialogWidth:400px;dialogHeight:400px;edge:sunken‘);
bubuko.com,布布扣 }
bubuko.com,布布扣</script>
bubuko.com,布布扣</HEAD>
bubuko.com,布布扣
bubuko.com,布布扣<BODY>
bubuko.com,布布扣<form>
bubuko.com,布布扣<input type="button" name="button" value="打开一个模态窗口" onclick="showModalWindow()">
bubuko.com,布布扣<input type="button" name="button" value="打开一个非模态窗口" onclick="showModellessWindow()">
bubuko.com,布布扣<BR>
bubuko.com,布布扣</form>
bubuko.com,布布扣</BODY>
bubuko.com,布布扣</HTML>
bubuko.com,布布扣
bubuko.com,布布扣------------------
bubuko.com,布布扣
bubuko.com,布布扣<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
bubuko.com,布布扣<HTML>
bubuko.com,布布扣<HEAD>
bubuko.com,布布扣<TITLE> New Document </TITLE>
bubuko.com,布布扣<SCRIPT LANGUAGE="JScript">
bubuko.com,布布扣function deWrite(){
bubuko.com,布布扣 var names=dialogArguments;//
bubuko.com,布布扣 document.write(names);
bubuko.com,布布扣}
bubuko.com,布布扣</SCRIPT>
bubuko.com,布布扣</HEAD>
bubuko.com,布布扣<BODY>
bubuko.com,布布扣<form>
bubuko.com,布布扣<input type="button" name="button" value="click me" onclick="deWrite()">
bubuko.com,布布扣</form>
bubuko.com,布布扣</BODY>
bubuko.com,布布扣</HTML>

其中window.Open(url,,)的一点体会

bubuko.com,布布扣<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
bubuko.com,布布扣<HTML>
bubuko.com,布布扣<HEAD>
bubuko.com,布布扣<TITLE> New Document </TITLE>
bubuko.com,布布扣<script language="javascript">
bubuko.com,布布扣 function showOpenWindow(){
bubuko.com,布布扣  window.open(‘http://www.sohu.com‘,‘xmddl‘,‘height=600px,width=800px,toolbar=no,menubar=no,resizable=yes, scrollbars=yes, location=no, status=no‘);
bubuko.com,布布扣 }
bubuko.com,布布扣</script>
bubuko.com,布布扣</HEAD>
bubuko.com,布布扣
bubuko.com,布布扣<BODY>
bubuko.com,布布扣<form>
bubuko.com,布布扣 <input type="button" name="button" value="click me" onclick="showOpenWindow()">
bubuko.com,布布扣</form>
bubuko.com,布布扣</BODY>
bubuko.com,布布扣</HTML>

//在Url的地方可以跟上一个.do的请求,基于struts架构时可以链接到某一个具体的页面,体现了窗口作为显示的作用
 
   //在模态窗口打开新窗口
在模态窗口的head部分添加如下代码
  <base targat=‘_self‘>

模态窗口和非模态窗口

标签:style   blog   http   ar   io   color   os   使用   sp   

原文地址:http://www.cnblogs.com/ajunForNet/p/4170760.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!