asp.net中彈窗及對話框

来源:互联网 发布:宠物用品软件排行 编辑:程序博客网 时间:2024/06/05 09:05

asp.net中彈窗及對話框

 

1.彈窗
使用window.open,這種方式的彈窗可以被用戶關閉而不返回值,而且不會一直保持在最上層.
--1.最基本的弹出窗口代码

<SCRIPT LANGUAGE="javascript"> 
<!-- 
window.open (
'page.html'
--> 
</SCRIPT> 

--2.经过设置后的弹出窗口

<SCRIPT LANGUAGE="javascript"> 
<!-- 
window.open (
'HTMLPage.htm''newwindow''height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'
--> 
</SCRIPT> 

--3.用函数控制弹出窗口

    <SCRIPT LANGUAGE="javascript"> 
<!-- 
function openwin() {
window.open (
'HTMLPage.htm''newwindow''height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'
}
--> 
</SCRIPT> 

調用函數:
<body onload='openwin()'>


--4.同时弹出2个窗口

    <SCRIPT LANGUAGE="javascript"> 
<!-- 
function openwin() {

window.open (
"HTMLPage.htm""newwindow""height=100, width=100, top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"

window.open (
"HTMLPage2.htm""newwindow2""height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"

}
--> 
</SCRIPT> 

要注意:兩個彈窗的name不能相同(但可以同時為空),否則只顯示後面那個彈窗.

--5.在一個頁面中彈窗
注:如果放在head區,則以下這段代碼裡不能有title,否則vs2005會報錯.

    <script language="JavaScript"> 
<!--
function openwin() 
{
OpenWindow
=window.open("""newwin""height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no"); 
OpenWindow.document.write(
"<TITLE>例子</TITLE>"
OpenWindow.document.write(
"<BODY BGCOLOR=#ffffff>"
OpenWindow.document.write(
"<h1>Hello!</h1>"
OpenWindow.document.write(
"New window opened!"
OpenWindow.document.write(
"</BODY>"
OpenWindow.document.write(
"</HTML>"
OpenWindow.document.close()

-->
    
</script>

--6.窗口之关闭
(1)定時自動關閉
在彈窗的head區加入:
<script language="JavaScript">
function closeit()
{setTimeout("self.close()",10000)}
</script>
在彈窗頁調用:
<body onload="closeit()">
(2)在彈窗中加一個關閉按鈕.
<FORM>
<INPUT TYPE='BUTTON' VALUE='关闭' onClick='window.close()'>
</FORM>

2.彈對話框
彈對話框有很多種方式,如window.alert(), window.confirm(),window.prompt(),在ie中還支持window.showModelessDialog,window.showModalDialog

--1.window.alert不能返回值,只能用於提示或警告.
格式:alert(str)
參數說明:str為提示的內容文字
例1:
<input id="Button2" type="button" onclick="javascript:alert('點了')"  value="button" />

--2.window.confirm只能返回true或false
格式:vReturnValue = confirm(str)
參考說明:str為為提示的內容文字
例1:
在page_load中加   
  this.Button1.Attributes.Add("onclick","javascript:return  window.confirm('are   you   sure?')");   

    protected void Button1_Click(object sender, EventArgs e)
    {
        //如果點"確定",則執行這段代碼
    }

--3.window.prompt返回一個字符串
格式:window.prompt(str,sDef)
參數說明:
str為提示文字,sDef為默認值
例1:
<script language=javascript> 
<!-- 
     function pro() 
     { 
         var tempA=window.prompt('请输入你的姓名',''); 
         if( tempA=="" || tempA==null ) 
         { 
             tempA="你没有输入任何文字"; 
         }  
         alert(tempA); 
     } 
--> 
</script> 
<body onload="pro()"></body>


--4.window.showModalDialog(IE 4+ 支持)模态对话框
這個可用於做多項選擇,數據篩選
格式:vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
参数说明:
sURL--必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
vArguments--可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等,对于字符串类型,最大为4096个字符。对话框通过window.dialogArguments来取得传递进来的参数。
sFeatures--可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。
1.dialogHeight :对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
2.dialogWidth: 对话框宽度。
3.dialogLeft: 离屏幕左的距离。
4.dialogTop: 离屏幕上的距离。
5.center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
6.help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
7.resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
8.status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
9.scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。
下面几个属性是用在HTA中的,在一般的网页中一般不使用。
10.dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
11.edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
12.unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。

例1:
在主頁面傳參:
<script language="JavaScript">
<!--
     var mxh1 = new Array("mxh","net_lover","孟子E章")
     window.showModalDialog("HTMLPage.htm",mxh1)
 -->
</script>
在HTMLPage.htm中取得參數:
<script>
  var a = window.dialogArguments
  alert("您传递的参数为:" + a)
</script>

例2:
test4.htm
在主頁面中彈出對話框:
<script>
  var a = window.showModalDialog("test5.htm")
  for(i=0;i<a.length;i++) alert(a[i])
</script>

在test5.htm中將值返回給主頁面並關閉自已:
 <script>
 function sendTo()
 {
  var a=new Array("a","b")
  window.returnValue = a
  window.close()
 }
 </script>

 <input value="返回" type=button onclick="sendTo()">

--5.window.showModelessDialog (IE 5+ 支持)非模态对话框
這個可以用來做廣告或通知.
格式:vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])
參數說明:同showModalDialog

 

原创粉丝点击