---
title: "jq ui.dialog.js简介"
author: "mfan"
date: "2011-07-19T00:08:18Z"
tags: []
categories: ["Web前端"]
slug: "jq-ui-dialog-js"
draft: false
lastmod: "2011-07-19T00:08:18Z"
id: 1127454
url: "https://mfan.iteye.com/blog/1127454"
---

001. ·概述
002. 一个浮动的窗口，包含标题和内容两部分。可以移动，调整大小，以及关闭图标 '×' 。
003. 如果内容长度超过了对话框内容区域的显示，则会自动出现滚动条。
004. 除此之外，还有一些常用的选项，如：添加底部按钮栏、模式窗口屏蔽层等。
005. 官方示例地址：http: //jqueryui.com/demos/dialog/
006. ·参数（名称 : 参数类型 : 默认值）
007. autoOpen : Boolean :  **true**
008. 如果设置为 **true** ，则默认页面加载完毕后，就自动弹出对话框；相反则处理hidden状态。
009. 初始：$( '.selector' ).dialog({ autoOpen:  **false**  });
010. 获取： **var**  autoOpen = $( '.selector' ).dialog( 'option' ,  'autoOpen' );
011. 设置：$( '.selector' ).dialog( 'option' ,  'autoOpen' ,  **false** );
012. bgiframe : Boolean :  **false**
013. 如果设置为 **true** ，则调用bgiframe插件，用于修复在IE6浏览器中无法显示于其它控件（select,flash）之上的问题。
014. 初始：$( '.selector' ).dialog({ bgiframe:  **true**  });
015. 获取： **var**  bgiframe = $( '.selector' ).dialog( 'option' ,  'bgiframe' );
016. 设置：$( '.selector' ).dialog( 'option' ,  'bgiframe' ,  **true** );
017. buttons : Object : { }
018. 为对话框添加相应的按钮及处理函数。
019. 初始：$( '.selector' ).dialog({ buttons: {  "Ok" :  **function** () { $( **this** ).dialog( "close" ); } } });
020. 获取： **var**  buttons = $( '.selector' ).dialog( 'option' ,  'buttons' );
021. 设置：$( '.selector' ).dialog( 'option' ,  'buttons' , {  "Ok" :  **function** () { $( **this** ).dialog( "close" ); } });
022. closeOnEscape : Boolean :  **true**
023. 设置当对话框打开的时候，用户按ESC键是否关闭对话框。
024. 初始：$( '.selector' ).dialog({ closeOnEscape:  **false**  });
025. 获取： **var**  closeOnEscape = $( '.selector' ).dialog( 'option' ,  'closeOnEscape' );
026. 设置：$( '.selector' ).dialog( 'option' ,  'closeOnEscape' ,  **false** );
027. dialogClass : String :  ''
028. 设置指定的类名称，它将显示于对话框的标题处。
029. 初始：$( '.selector' ).dialog({ dialogClass:  'alert'  });
030. 获取： **var**  dialogClass = $( '.selector' ).dialog( 'option' ,  'dialogClass' );
031. 设置：$( '.selector' ).dialog( 'option' ,  'dialogClass' ,  'alert' );
032. draggable : Boolean :  **true**
033. 如果设置为 **true** ，则允许拖动对话框的标题栏移动窗口。
034. 初始：$( '.selector' ).dialog({ draggable:  **false**  });
035. 获取： **var**  draggable = $( '.selector' ).dialog( 'option' ,  'draggable' );
036. 设置：$( '.selector' ).dialog( 'option' ,  'draggable' ,  **false** );
037. height : Number :  'auto'
038. 设置对话框的高度（单位：像素）。
039. 初始：$( '.selector' ).dialog({ height: 530 });
040. 获取： **var**  height = $( '.selector' ).dialog( 'option' ,  'height' );
041. 设置：$( '.selector' ).dialog( 'option' ,  'height' , 530);
042. hide : String :  **null**
043. 使对话框关闭（隐藏），可添加动画效果。
044. 初始：$( '.selector' ).dialog({ hide:  'slide'  });
045. 获取： **var**  hide = $( '.selector' ).dialog( 'option' ,  'hide' );
046. 设置：$( '.selector' ).dialog( 'option' ,  'hide' ,  'slide' );
047. maxHeight : Number :  **false**
048. 设置对话框的最大高度（单位：像素）。
049. 初始：$( '.selector' ).dialog({ maxHeight: 400 });
050. 获取： **var**  maxHeight = $( '.selector' ).dialog( 'option' ,  'maxHeight' );
051. 设置：$( '.selector' ).dialog( 'option' ,  'maxHeight' , 400);
052. maxWidth : Number :  **false**
053. 设置对话框的最大宽度（单位：像素）。
054. 初始：$( '.selector' ).dialog({ maxWidth: 600 });
055. 获取： **var**  maxWidth = $( '.selector' ).dialog( 'option' ,  'maxWidth' );
056. 设置：$( '.selector' ).dialog( 'option' ,  'maxWidth' , 600);
057. minHeight : Number : 150
058. 设置对话框的最小高度（单位：像素）。
059. 初始：$( '.selector' ).dialog({ minHeight: 300 });
060. 获取： **var**  minHeight = $( '.selector' ).dialog( 'option' ,  'minHeight' );
061. 设置：$( '.selector' ).dialog( 'option' ,  'minHeight' , 300);
062. minWidth : Number : 150
063. 设置对话框的最小宽度（单位：像素）。
064. 初始：$( '.selector' ).dialog({ minWidth: 400 });
065. 获取： **var**  minWidth = $( '.selector' ).dialog( 'option' ,  'minWidth' );
066. 设置：$( '.selector' ).dialog( 'option' ,  'minWidth' , 400);
067. modal : Boolean :  **false**
068. 是否为模式窗口。如果设置为 **true** ，则在页面所有元素之前有个屏蔽层。
069. 初始：$( '.selector' ).dialog({ modal:  **true**  });
070. 获取： **var**  modal = $( '.selector' ).dialog( 'option' ,  'modal' );
071. 设置：$( '.selector' ).dialog( 'option' ,  'modal' ,  **true** );
072. position : String, Array :  'center'
073. 设置对话框的初始显示位置。可选值:  'center' ,  'left' ,  'right' ,  'top' ,  'bottom' , 或是一个数组\[ 'right' , 'top' ]
074. 初始：$( '.selector' ).dialog({ position:  'top'  });
075. 获取： **var**  position = $( '.selector' ).dialog( 'option' ,  'position' );
076. 设置：$( '.selector' ).dialog( 'option' ,  'position' ,  'top' );
077. resizable : Boolean :  **true**
078. 设置对话框是否可以调整大小。
079. 初始：$( '.selector' ).dialog({ resizable:  **false**  });
080. 获取： **var**  resizable = $( '.selector' ).dialog( 'option' ,  'resizable' );
081. 设置：$( '.selector' ).dialog( 'option' ,  'resizable' ,  **false** );
082. show : String :  **null**
083. 用于显示对话框。
084. 初始：$( '.selector' ).dialog({ show:  'slide'  });
085. 获取： **var**  show = $( '.selector' ).dialog( 'option' ,  'show' );
086. 设置：$( '.selector' ).dialog( 'option' ,  'show' ,  'slide' );
087. stack : Boolean :  **true**
088. 设置移动时对话框是否前置于其它的对话框前面。
089. 初始：$( '.selector' ).dialog({ stack:  **false**  });
090. 获取： **var**  stack = $( '.selector' ).dialog( 'option' ,  'stack' );
091. 设置：$( '.selector' ).dialog( 'option' ,  'stack' ,  **false** );
092. title : String :  ''
093. 指定对话框的标题，也可以在对话框附加元素的title属性中设置标题。
094. 初始：$( '.selector' ).dialog({ title:  'Dialog Title'  });
095. 获取： **var**  title = $( '.selector' ).dialog( 'option' ,  'title' );
096. 设置：$( '.selector' ).dialog( 'option' ,  'title' ,  'Dialog Title' );
097. width : Number : 300
098. 设置对话框的宽度（单位：像素）。
099. $( '.selector' ).dialog({ width: 460 });
100. 获取： **var**  width = $( '.selector' ).dialog( 'option' ,  'width' );
101. 设置：$( '.selector' ).dialog( 'option' ,  'width' , 460);
102. zIndex : Integer : 1000
103. 设置对话框的zindex值。
104. 初始：$( '.selector' ).dialog({ zIndex: 3999 });
105. 获取： **var**  zIndex = $( '.selector' ).dialog( 'option' ,  'zIndex' );
106. 设置：$( '.selector' ).dialog( 'option' ,  'zIndex' , 3999);
107. ·事件
108. beforeclose : dialogbeforeclose
109. 当对话框关闭之前，触发此事件。如果返回 **false** ，则对话框仍然显示。
110. 初始：$( '.selector' ).dialog({ beforeclose:  **function** (event, ui) { ... } });
111. 绑定：$( '.selector' ).bind( 'dialogbeforeclose' ,  **function** (event, ui) { ... });
112. open : dialogopen
113. 当对话框打开后，触发此事件。
114. 初始：$( '.selector' ).dialog({ open:  **function** (event, ui) { ... } });
115. 绑定：$( '.selector' ).bind( 'dialogopen' ,  **function** (event, ui) { ... });
116. focus : dialogfocus
117. 当对话框获取焦点时，触发此事件。
118. 初始：$( '.selector' ).dialog({ focus:  **function** (event, ui) { ... } });
119. 绑定：$( '.selector' ).bind( 'dialogfocus' ,  **function** (event, ui) { ... });
120. dragStart : dragStart
121. 当开始拖拽对话框移动时，触发此事件。
122. 初始：$( '.selector' ).dialog({ dragStart:  **function** (event, ui) { ... } });
123. 绑定：$( '.selector' ).bind( 'dragStart' ,  **function** (event, ui) { ... });
124. drag : drag
125. 当拖拽对话框移动时，触发此事件。
126. 初始：$( '.selector' ).dialog({ drag:  **function** (event, ui) { ... } });
127. 绑定：$( '.selector' ).bind( 'drag' ,  **function** (event, ui) { ... });
128. dragStop : dragStop
129. 当拖拽对话框动作结束时，触发此事件。
130. 初始：$( '.selector' ).dialog({ dragStop:  **function** (event, ui) { ... } });
131. 绑定：$( '.selector' ).bind( 'dragStop' ,  **function** (event, ui) { ... });
132. resizeStart : resizeStart
133. 当开始改变对话框大小时，触发此事件。
134. 初始：$( '.selector' ).dialog({ resizeStart:  **function** (event, ui) { ... } });
135. 绑定：$( '.selector' ).bind( 'resizeStart' ,  **function** (event, ui) { ... });
136. resize : resize
137. 当对话框大小改变时，触发此事件。
138. 初始：$( '.selector' ).dialog({ resize:  **function** (event, ui) { ... } });
139. 绑定：$( '.selector' ).bind( 'resize' ,  **function** (event, ui) { ... });
140. resizeStop : resizeStop
141. 当对话框大小改变结束时，触发此事件。
142. 初始：$( '.selector' ).dialog({ resizeStop:  **function** (event, ui) { ... } });
143. 绑定：$( '.selector' ).bind( 'resizeStop' ,  **function** (event, ui) { ... });
144. close : dialogclose
145. 当对话框关闭后，触发此事件。
146. 初始：$( '.selector' ).dialog({ close:  **function** (event, ui) { ... } });
147. 绑定：$( '.selector' ).bind( 'dialogclose' ,  **function** (event, ui) { ... });
148. ·属性
149. destroy
150. 销毁对话框对象。
151. 用法：.dialog(  'destroy'  )
152. disable
153. 禁用对话框。
154. 用法：.dialog(  'disable'  )
155. enable
156. 启用对话框。
157. 用法：.dialog(  'enable'  )
158. option
159. 获取或设置对话框的属性。
160. 用法：.dialog(  'option'  , optionName , \[value] )
161. close
162. 关闭对话框。
163. 用法：.dialog(  'close'  )
164. isOpen
165. 用于判断对话框是否处理打开状态。
166. 用法：.dialog(  'isOpen'  )
167. moveToTop
168. 将对话框移至最顶层显示。
169. 用法：.dialog(  'moveToTop'  )
170. open
171. 打开对话框。
172. 用法：.dialog(  'open'  )