jquery弹出框插件jquery.ui.dialog用法分析

jquery.ui.dialog是一个非常灵活的模式框,它的官方地址为:

2. 文件引用

要使用jquery.ui.dialog,需要引用两个文件,1个是js,另外1个是css

在contentpage中添加:

<script type="text/javascript" src="https://www.jb51.net/Content/ui.js"></script>

在masterpage中添加:

<link href="https://www.jb51.net/jquery-ui.css" type="text/css">

3. 使用方法

jquery.ui.dialog相比thinkbox要有优势,thinkbox是在$.ready中指定的,导致不能灵活的扩展弹出层的弹出时机,针对一个逻辑判断,一种情况下弹出,另外一种不弹出,thinkbox就缺乏应变能力,而jquery.ui.dialog()采用 $('..').dialog(..);的方式使得弹出更加灵活

1)弹出简单的对话框

$("#dialog").dialog();

2)弹出模式对话框

$("#dialog").dialog({ modal: true });

3)弹出模式对话框,并有遮罩效果

复制代码 代码如下:

$("#dialog").dialog({ modal: true, overlay: { opacity: 0.5, background: "black" } });

4)带确定与取消按钮

复制代码 代码如下:

$("#dialog").dialog({ buttons: { "Ok": function() { alert("Ok"); }, "Cancel": function() { $(this).dialog("close"); } } });


5)如何关闭对话框

$("#dialog").dialog("close");

<!DOCTYPE html> <html> <head> <link href="https://www.jb51.net/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" type="text/css"/> <script src="https://www.jb51.net/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="https://www.jb51.net/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <script> $(document).ready(function() { $("#dialog").dialog(); }); </script> </head> <body> <div title="Dialog Title">I'm in a dialog</div> </body> </html>

<!DOCTYPE html> <html> <head> <link href="https://www.jb51.net/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" type="text/css"/> <script src="https://www.jb51.net/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="https://www.jb51.net/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <script> $(document).ready(function() { $("#dialog").dialog(); }); </script> </head> <body> <div title="Dialog Title">I'm in a dialog</div> </body> </html>

 jQuery boxy

使用该jQuery插件

要想使用该jQuery插件,需要把$(selector).boxy();放在document.ready中。使用合适的选择器表达式替换这里的"selector",例如:"a[rel=boxy],form.with-confirmation"。这会给匹配的元素附加一些行为,如下:

① 一个href属性中如果锚点包含#,则此锚点相对应的ID的DOM元素的内容就会被添加到boxy对话框中。

② 如果href锚点内容为其他一些东西,则会试图使用Ajax载入其对应的内容。理想情况下,我们有相同的起源检查和委托对框架的跨域请求。这将会在下面展示。

③ 表单上会显示一个提交模式的确认消息。

使用方法

使用下载包中的三个文件!

<script type ="text/javascript " src ="../js/jquery.boxy.js "> </script>
<link rel ="stylesheet " href ="../css/boxy.css " type ="text/css " />

基本的插件用法:

<script type="text/javascript"> $(function(){ $(".boxy").boxy(); }); </script>

请注意,boxy对话框自动计算出您的内容区域内本身的大小和位置,没有必要明确规定了包装集的尺寸。

<link rel ="stylesheet" href ="https://www.jb51.net/css/common.css" type ="text/css" />

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery拖拽特效与技巧总结》、《jQuery表格(table)操作技巧汇总》、《jquery中Ajax用法总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》及《jquery选择器用法总结

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzfxpd.html