JQuery UI库 - Dialog

在网站中我们经常会做一些好看的Popup Dialog,我们前面曾经讲过用JQuery的Importo插件
来做自定义的AlertBox。
其实,我们可以利用JQuery官方提供的UI库来做。
而且,JQuery UI库效果更好,更成熟。

今天,我们就来讲一下怎么利用JQuery UI自身的UI库来做自定义的Dialog。

首先,我们需要下载到JQuery UI自身的javascript和css还有图片文件夹,把它们
放在特定的位置,我们好引用。
jquery-ui-1.7.2.custom.min.js
jquery-ui-1.7.2.custom.css

完整代码如下:
<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeBehind = " JqueryUIdialog.aspx.cs "  Inherits = " BlogNet.JQueryDemo.JqueryUIdialog "   %>

<! 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 > JQuery Dialog </ title >
  
< script  type ='text/javascript'  src ='../JsLib/jquery-1.3.2.min.js' ></ script >
  
< script  type ='text/javascript'  src ='../JsLib/jquery-ui-1.7.2.custom.min.js' ></ script >
  
< link  rel ='stylesheet'  type ='text/css'  href ='../CSS/jquery-ui-1.7.2.custom.css'  />
  
< link  rel ='StyleSheet'  href ='../CSS/style.css'  type ='text/css'  />
  
< script  type ='text/javascript' >
    $.ui.dialog.defaults.bgiframe 
=   true ;
    $(
function () {
      $(
' #myDialog ' ).dialog({
        width: 
700 ,
        autoOpen: 
false ,
        modal: 
true ,
        buttons: {
                    
        }
      });
    });    
      
    
function  showDialog() {
        $(
' #myDialog ' ).dialog( ' open ' );    
    }
    
    
function  closeWin() {
        $(
' #myDialog ' ).dialog( ' close ' );
    }
  
</ script >
</ head >
< body >
  
<!--  Jquery UI popup dialog content  -->
  
< div  id ="myDialog"  title ="My Dialog" >
      
< div  id ="dialogContent"  style ="overflow-y: auto; height: 400px;" >
          
< span  class ="blue13" > Here is your message for dialog </ span >
      
</ div >
      
< div  style ="text-align:right;" >
          
< img  src ="../Images/Button_Close.gif"  border ="none"  onMouseover ="this.style.cursor='hand'"  onclick ="closeWin();" >
      
</ div >
  
</ div >
  
  
< form  id ="form1"  runat ="server" >
  
< div >
    
< input  type ="button"  name ="btnDialog"  value ="My Dialog"  id ="btnDialog"  onclick ="javascript:showDialog();"   />
  
</ div >
  
</ form >
</ body >
</ html >

在上面代码中,<div id="dialogContent">用于放置dialog的主体内容,
我们可以在其中放图片等一些复杂的html。将overflow-y: auto;是为了
如果内容过长时可以滚动条进行滚动。
在下面我们设置一个div用来放置自己的image按钮图片。
我们也可以采用dialog自身的关闭按钮,只需要在buttons: { 中间加入 }。
eg:  Ok: $('#myDialog').dialog('close');

效果如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值