


The dialog box function in the jQuery UI library uses full parsing_jquery
Dialog is a very important function of jQuery UI. It completely replaces JavaScript
alert(), prompt() and other methods also avoid the complexity and redundancy of new windows or pages.
1. Open multiple dialogs
Just set different ids to achieve this.
$('#x').dialog(); $('#y').dialog();
2. Modify dialog style
In the pop-up dialog box, open Firebug in Firefox or right-click ->View
element. You can look at the dialog style and modify the dialog title background.
//无须修改ui 里的CSS,直接用style.css 替代掉 .ui-widget-header { background:url(../img/xxx.png); }
3. Properties of dialog() method
Dialog methods have two forms: 1.dialog(options), options are in the form of object key-value pairs
Pass parameters, each key-value pair represents an option; 2.dialog('action', param), action is an operation pair
The string of the dialog box method, param is an option of options.
Attribute
|
Default value/type |
Description | |||||||||
title |
none/string$('#reg').dialog({ title : '注册', buttons : { '按钮' : function () {} } ); Copy after login |
The title of the dialog box can be set directly on the DOM element | |||||||||
buttons
|
None/Object
|
Add buttons to the dialog in the form of object key-value pairs. Keys are buttons<🎜>
The name of , the value is the callback function called after the user clicks <🎜>
|
Attribute<🎜> | Default value/type<🎜> | Description<🎜> |
position<🎜> | center/string<🎜> |
Set the coordinate position of a dialog window, the default is center. <🎜>
Other setting values are: left top, top right, bottom left, <🎜>
right bottom (four corners), top, bottom (top or bottom<🎜>
Heart, width centered), left or right (left or right, height<🎜>
center), center (default value) <🎜>
|
$('#reg').dialog({ position : 'left top' });
属性 |
默认值/类型 |
说明 |
width |
300/数值 |
对话框的宽度。默认为300,单位是像素。 |
height |
auto/数值 |
对话框的高度。默认为auto,单位是像素。 |
minWidth |
150/数值 |
对话框的最小宽度。默认150,单位是像素。 |
minHeight |
150/数值 |
对话框的最小高度。默认150,单位是像素。 |
maxWidth |
auto/数值 |
对话框的最大宽度。默认auto,单位是像素。 |
maxHeight |
auto/数值 |
对话框的最大高度。默认auto,单位是像素。 |
$('#reg').dialog({ height : 500, width : 500, minWidth : 300, minHeight : 300, maxWidth : 800, maxHeight : 600 });
属性 |
默认值/类型 |
说明 |
show |
false/布尔值 |
显示对话框时,默认采用淡入效果。 |
hide |
false 布尔值 |
关闭对话框时,默认采用淡出效果。 |
$('#reg').dialog({ show : true, hide : true });
注意:设置true 后,默认为淡入淡出,如果想使用别的特效,可以使用以下表格中的字符串参数。
特效名称 |
说明 |
blind |
对话框从顶部显示或消失 |
bounce |
对话框断断续续地显示或消失,垂直运动 |
clip |
对话框从中心垂直地显示或消失 |
slide |
对话框从左边显示或消失 |
drop |
对话框从左边显示或消失,有透明度变化 |
fold |
对话框从左上角显示或消失 |
highlight |
对话框显示或消失,伴随着透明度和背景色的变化 |
puff |
对话框从中心开始缩放。显示时“收缩”,消失时“生长” |
scale |
对话框从中心开始缩放。显示时“生长”,消失时“收缩” |
pulsate |
对话框以闪烁形式显示或消失 |
$('#reg').dialog({ show : 'blind', hide : 'blind' });
属性 |
默认值/类型 |
说明 |
autoOpen |
true/布尔值 |
默认为true,调用dialog()方法时就会打开对话框;
如果为false,对话框不可见,但对话框已创建,可
以通过dialog('open')才能可见。
|
draggable |
true/布尔值 |
默认为true,可以移动对话框,false 无法移动。 |
resizable |
true/布尔值 |
默认为true,可以调整对话框大小,false 无法调整 |
modal |
false/布尔值 |
默认为false,对话框外可操作,true 对话框会遮罩
一层灰纱,无法操作。
|
closeText |
无/字符串 |
设置关闭按钮的title 文字 |
$('#reg').dialog({ autoOpen : false, draggable : false, resizable : false, modal : true, closeText : '关闭' });
四.dialog()方法的事件
除了属性设置外,dialog()方法也提供了大量的事件。这些事件可以给各种不同状态
时提供回调函数。这些回调函数中的this 值等于对话框内容的div 对象,不是整个对话框
的div。
事件名 |
说明 |
focus |
当对话框被激活时(首次显示以及每次在上面点击)会
调用focus 方法,该方法有两个参数(event, ui)。此事件中
的ui 参数为空。
|
create |
当对话框被创建时会调用create 方法,该方法有两个参
数(event, ui)。此事件中的ui 参数为空。
|
open |
当对话框被显示时(首次显示或调用dialog('open')方法)
会调用open 方法,该方法有两个参数(event, ui)。此事件
中的ui 参数为空。
|
beforeClose |
当对话框将要关闭时( 当单击关闭按钮或调用
dialog('close')方法),会调用beforeclose 方法。如果该函
数返回false,对话框将不会被关闭。关闭的对话框可以
用dialog('open')重新打开。该方法有两个参数(event, ui)。
此事件中的ui 参数为空。
|
close |
当对话框将要关闭时( 当单击关闭按钮或调用
dialog('close')方法),会调用close 方法。关闭的对话框可
以用dialog('open')重新打开。该方法有两个参数(event,
ui)。此事件中的ui 参数为空。
|
drag |
当对话框移动时,每次移动一点均会调用drag 方法。该
方法有两个参数。该方法有两个参数(event, ui)。此事件
中的ui 有两个属性对象:
1.position,得到当前移动的坐标,有两个子属性:top 和
left。
2.offset,得到当前移动的坐标,有两个子属性:top 和left。
|
dragStart |
当开始移动对话框时,会调用dragStart 方法。该方法有
两个参数(event, ui)。此事件中的ui 有两个属性对象: 1.position, get the current moving coordinates, has two sub-properties: top and
left.
2.offset, get the current moving coordinates, has two sub-properties: top and left.
|
dragStop |
When the dialog box starts to be moved, the dragStop method is called. This method has
Two parameters (event, ui). The ui in this event has two attribute objects:
1.position, get the current moving coordinates, has two sub-properties: top and
left.
2.offset, get the current moving coordinates, has two sub-properties: top and left.
|
resize |
When the dialog box is increased in size, resize will be called every time you drag it.
Method. This method has two parameters (event, ui). There are four ui in this event
attribute objects:
1.size, gets the size of the dialog box, has two sub-properties: width and
height.
2.position, get the coordinates of the dialog box, has two sub-properties: top and left.
3.originalSize, get the original size of the dialog box, has two sub-properties:
width and height.
4.originalPosition, get the original coordinates of the dialog box, there are two sub-attributes
Sex: top and left.
|
resizeStart |
When starting to drag the dialog box, the resizeStart method will be called. This method has
Two parameters (event, ui). The ui in this event has four attribute objects:
1.size, gets the size of the dialog box, has two sub-properties: width and
height.
2.position, get the coordinates of the dialog box, has two sub-properties: top and left.
3.originalSize, get the original size of the dialog box, has two sub-properties:
width and height.
4.originalPosition, get the original coordinates of the dialog box, there are two sub-attributes
Sex: top and left.
|
resizeStop |
When the drag dialog box is ended, the resizeStart method will be called. This method has
Two parameters (event, ui). The ui in this event has four attribute objects:
1.size, gets the size of the dialog box, has two sub-properties: width and
height.
2.position, get the coordinates of the dialog box, has two sub-properties: top and left.
3.originalSize, get the original size of the dialog box, has two sub-properties:
width and height.
4.originalPosition, get the original coordinates of the dialog box, there are two sub-attributes
Sex: top and left.
|
//当对话框获得焦点后 $('#reg').dialog({ focus : function (e, ui) { alert('获得焦点'); } }); //当创建对话框时 $('#reg').dialog({ create : function (e, ui) { alert('创建对话框'); } }); //当将要关闭时 $('#reg').dialog({ beforeClose : function (e, ui) { alert('关闭前做的事!'); return flag; } }); //关闭对话框时 $('#reg').dialog({ close : function (e, ui) { alert('关闭!'); } }); //对话框移动时 $('#reg').dialog({ drag : function (e, ui) { alert('top:' + ui.position.top + '\n' + 'left:' + ui.position.left); } }); //对话框开始移动时 $('#reg').dialog({ dragStart : function (e, ui) { alert('top:' + ui.position.top + '\n' + 'left:' + ui.position.left); } }); //对话框结束移动时 $('#reg').dialog({ dragStop : function (e, ui) { alert('top:' + ui.position.top + '\n' + 'left:' + ui.position.left); } }); //调整对话框大小时 $('#reg').dialog({ resize : function (e, ui) { alert('size:' + ui.size.width + '\n' + 'originalSize:' + ui.originalSize.width); } }); //开始调整对话框大小时 $('#reg').dialog({ resizeStart : function (e, ui) { alert('size:' + ui.size.width + '\n' + 'originalSize:' + ui.originalSize.width); } }); //结束调整对话框大小时 $('#reg').dialog({ resizeStop : function (e, ui) { alert('size:' + ui.size.width + '\n' + 'originalSize:' + ui.originalSize.width); } });
方法 |
返回值 |
说明 |
dialog('open') |
jQuery 对象 |
打开对话框 |
dialog('close') |
jQuery 对象 |
关闭对话框 |
dialog('destroy') |
jQuery 对象 |
删除对话框,直接阻断了dialog |
dialog('isOpen') |
布尔值 |
判断对话框是否打开状态 |
dialog('widget') |
jQuery 对象 |
获取对话框的jQuery 对象 |
dialog('option', param) |
一般值 |
获取options 属性的值 |
dialog('option', param, value) |
jQuery 对象 |
设置options 属性的值 |
//初始隐藏对话框 $('#reg').dialog({ autoOpen : false }); //打开对话框 $('#reg_a').click(function () { $('#reg').dialog('open'); }); //关闭对话框 $('#reg').click(function () { $('#reg').dialog('close'); }); //判断对话框打开或关闭状态 $(document).click(function () { alert($('#reg').dialog('isOpen')); }); //将指定对话框置前 $(document).click(function () { $('#reg').dialog('moveToTop'); }); //获取某个options 的param 选项的值 var title = $('#reg').dialog('option', 'title'); alert(title); //设置某个options 的param 选项的值 $('#reg').dialog('option', 'title', '注册');
五.dialog 中使用on()
在dialog 的事件中,提供了使用on()方法处理的事件方法。
特效名称 |
说明 |
dialogfocus |
得到焦点时触发 |
dialogopen |
显示时触发 |
dialogbeforeclose |
将要关闭时触发 |
dialogclose |
关闭时触发 |
dialogdrag |
每一次移动时触发 |
dialogdragstart |
开始移动时触发 |
dialogdragstop |
移动结束后触发 |
dialogresize |
每次调整大小时触发 |
dialogresizestart |
开始调整大小时触发 |
dialogresizestop |
结束调整大小时触发 |
$('#reg').on('dialogclose', function () { alert('关闭'); });

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
