jQuery UI dialog 參数说明

前段时间碰到个问题 jquery UI dialog弹出层 弹出多个层是 比方弹出两个层A和B  B层假设显示的数据表格太大,伸到了A层的外面,那伸到A层以外的部分就看不到了,因为B层是在A层上弹出的 B的大小受到A层大小的限制css

因而找到了这个资料 保存下来html

-----------------------------------------------------------------------------------------------------jquery

初始化參数chrome

对于 dialog 来讲,首先需要进行初始化,在调用 dialog 函数的时候,假设没有传递參数,或者传递了一个对象,那么就表示在初始化一个对话框。数组

没有參数,表示依照默认的设置初始化对话框,在当前最新版本号的 jQuery UI 1.8.9 中, dialog 支持下列属性。ide

autoOpen   初始化以后,是否立刻显示对话框,默以为 true函数

modal        是否模式对话框,默以为 falseui

closeOnEscape   当用户按 Esc 键以后,是否应该关闭对话框,默以为 truethis

draggable  是否赞成拖动,默以为 truespa

resizable    可否够调整对话框的大小,默以为 true

title           对话框的标题,可以是 html 串,好比一个超级连接。

position     用来设置对话框的位置,有三种设置方法

     1.  一个字符串,赞成的值为  'center', 'left', 'right', 'top', 'bottom'.  此属性的默认值即为 'center',表示对话框居中。
     2.  一个数组,包括两个以像素为单位的位置,好比, 

var  dialogOpts  =  {
    position: [
100 100 ]
};

     3. 一个字符串组成的数组,好比, ['right','top'],表示对话框将会位于窗体的右上角。

var  dialogOpts  =  {
    position: [
" left " " bottom " ]
};

 

一组关于尺寸的属性,以像素为单位。

width     宽度, 默认 300

height    高度,默认 'auto'

minWidth     最小宽度,默认 150

minHeight    最小高度,默认 150

maxWidth   最大宽度

maxHeight   最大高度

 

还有关于关闭的效果

hide       当对话框关闭时的效果,默以为 null, 好比, hide: 'slide'

show     当对话框打开时的效果。默以为 null

 

堆叠

stack     对话框是否叠在其它对话框之上。默以为 true

zIndex   对话框的 z-index 值,一个整数,越大越在上面。默认 1000

 

button

buttons   一个对象,属性名将会被做为button的提示文字,属性值为一个函数,即button的处理函数。

var  dialogOpts  =  {
   buttons: {
      
" Ok " function () { } ,
      
" Cancel " function () {}
   }
}
$(
" #myDialog " ).dialog(dialogOpts);

 

IE6 的 select 元素穿透问题

bgiframe     解决 IE6 的 select 元素穿透问题,经过添加一个 iframe 来解决。默以为  true

这一功能需要使用脚本 jquery.bgiframe-2.1.2,脚本在 jQuery UI 压缩包中 development-bundle/external 目录中,需要将这个文件增长到页面中。

< script src = " ../jquery-1.4.4.js " >< / script>
< script src = " ../external/jquery.bgiframe-2.1.2.js " >< / script>
< script src = " ../ui/jquery.ui.core.js " >< / script>

 

这个控件现在有一个bug,在弹出窗体有遮罩层的状况下,在chrome下,假设出现纵向滚动栏,没法用鼠标拖动,仅仅能使用滚轮。

上边的说明来自 王洋

设置前

设置后

 

演示样例

$( " #dialog " ).dialog({
    bgiframe: 
true ,
    resizable: 
false ,
    height:
140 ,
    modal: 
true ,
    overlay: {
        backgroundColor: 
' #000 ' ,
        opacity: 
0.5
    },
    buttons: {
        
' Delete all items in recycle bin ' function () {
            $(
this ).dialog( ' close ' );
        },
        Cancel: 
function () {
            $(
this ).dialog( ' close ' );
        }
    }
});

效果例如如下。

 

对话框的方法

初始化以后,就可以使用对话框了,比方说打开对话框,关闭对话框,这需要经过对话框的方法来完毕。

对话框的方法需要经过调用 dialog 函数,并传递字符串形式的方法来完毕。好比,dialog( "open" )  表示调用对话框的 open 方法。

open     打开对话框,需要注意的是,并无 open() 方法,而是经过 dialog( "open" ) 来调用。好比,  .dialog( "open" )

close     关闭对话框

$( this ).dialog( ' close ' );

destroy  摧毁一个对话框,去除对话框功能,将元素还原为初始化以前的状态。

isOpen   检查对话框的状态,假设已经打开,返回 true.

moveToTop  将对话框移到对话框的顶端

option    设置或者读取对话框某个属性的值,有两种使用方法。

    假设第二个參数为字符串,假设提供了三个參数,表示设置,假设两个參数,表示读取。 好比 .dialog( "option" , optionName , [value] )

    假设第二个參数为对象,表示一次性设置多个属性。

enable   启用对话框

disable  禁用对话框

对话框的事件

在对话框使用过程当中,还将触发多种事件,咱们可以本身定义事件处理函数进行响应。

create

open

focus

dragStart

drag

dragStop

resizeStart

resize

resizeStop

beforeClose

close

好比,如下的设置了 open,close,beforeClose 的事件处理,显示窗体的状态。

var  dialogOpts  =  {
     open: 
function () {
             $(
" #status " ).find( " .ui-widget-content " ).text( " The dialog is open " );
         },
     close: 
function () {
             $(
" #status " ).find( " .ui-widget-content " ).text( " The dialog is closed " );
         },
     beforeclose: 
function () {
             
if  (parseInt($( " .ui-dialog " ).css( " width " ))  ==   300   ||
                 parseInt($(
" .ui-dialog " ).css( " height " ))  ==   300 ) {
               
return   false
             }
         }
};
$(
" #myDialog " ).dialog(dialogOpts);

 效果例如如下

 

对话框使用常见问题

常见的问题就是屡次初始化一个对话框。

对话框只需要初始化一次,屡次初始化会有问题。

相关文章
相关标签/搜索