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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

xiangqian0505   2020-05-15 我要评论

本文实例讲述了jquery弹出框插件jquery.ui.dialog用法。分享给大家供大家参考,具体如下:

1. jquery.ui.dialog

官方地址 http://jqueryui.nethttps://img.qb5200.com/download-x/dialog/

jquery.ui.dialog是一个非常灵活的模式框,它的官方地址为: http:/https://img.qb5200.com/download-x/docs.jquery.com/UI/Dialog

2. 文件引用

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

在contentpage中添加:

<script type="text/javascript" src="/Content/ui.js"></script>

在masterpage中添加:

<link href="jquery-ui.css" rel="stylesheet" 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="/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
 <script src="/ajax/libs/jquery/1.5/jquery.min.js"></script>
 <script src="/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
 <script>
 $(document).ready(function() {
  $("#dialog").dialog();
 });
 </script>
</head>
<body style="font-size:62.5%;">
<div id="dialog" title="Dialog Title">I'm in a dialog</div>
</body>
</html>

<!DOCTYPE html>
<html>
<head>
 <link href="/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
 <script src="/ajax/libs/jquery/1.5/jquery.min.js"></script>
 <script src="/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
 <script>
 $(document).ready(function() {
  $("#dialog").dialog();
 });
 </script>
</head>
<body style="font-size:62.5%;">
<div id="dialog" 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 ="../css/common.css" type ="text/css" />

希望本文所述对大家jQuery程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们