歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> jQuery的插件 --- 對話框的效果 (有遮罩效果)

jQuery的插件 --- 對話框的效果 (有遮罩效果)

日期:2017/3/1 10:25:40   编辑:Linux編程

jQuery的插件 --- 對話框的效果 (有遮罩效果)

  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html>
  8. <head>
  9. <base href="<%=basePath%>">
  10. <title>My JSP 'dialog.jsp' starting page</title>
  11. <meta http-equiv="pragma" content="no-cache">
  12. <meta http-equiv="cache-control" content="no-cache">
  13. <meta http-equiv="expires" content="0">
  14. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  15. <meta http-equiv="description" content="This is my page">
  16. <!--
  17. <link rel="stylesheet" type="text/css" href="styles.css">
  18. -->
  19. <script type="text/javascript"
  20. src="${pageContext.request.contextPath}/js/jquery-1.7.1.min.js">
  21. </script>
  22. <script type="text/javascript"
  23. src="${pageContext.request.contextPath}/js/jquery-ui-1.8.18.custom.min.js">
  24. </script>
  25. <link rel="stylesheet" type="text/css"
  26. href="${pageContext.request.contextPath}/css/ui-lightness/jquery-ui-1.8.18.custom.css">
  27. <style type="text/css">
  28. body {
  29. font: 62.5% "Trebuchet MS", sans-serif;
  30. margin: 50px;
  31. }
  32. #dialog_link {
  33. padding: .4em 1em .4em 20px;
  34. text-decoration: none;
  35. position: relative;
  36. }
  37. #dialog_link span.ui-icon {
  38. margin: 0 5px 0 0;
  39. position: absolute;
  40. left: .2em;
  41. top: 50%;
  42. margin-top: -8px;
  43. }
  44. </style>
  45. <script type="text/javascript">
  46. //頁面加載完畢觸發匿名函數
  47. $(document).ready(function() {
  48. //點擊事件處理 打開dialog
  49. $("#dialog_link").click(function() {
  50. //打開窗口
  51. //alter("fdsf");//沒有返回值 會跳轉頁
  52. $("#dialog").dialog("open");
  53. return false;//返回值為false,不去執行<a href="#"></a>連接的操作
  54. });
  55. //dialog注冊
  56. //當你把$("#dialog")注冊為對話框時,$("#dialog")的內容也將被隱藏掉
  57. $("#dialog").dialog( {
  58. autoOpen : false,//設置對話框是否打開 ,如果為false,則���打開 ,如果為true,則自動打開,默認值為fallse,文本也將被隱藏
  59. //width:600,//寬度的設置
  60. /*height:300*/
  61. buttons : {
  62. "確定" : function() {
  63. $(this).dialog("close");
  64. },
  65. "取消 " : function() {
  66. $(this).dialog("close");
  67. }
  68. },
  69. bgiframe:false,
  70. closeOnEscapt:true,//默認值是true,當按下esc鍵的時候關閉窗口
  71. draggable:true, //拖拽的效果,默認是 true
  72. show:"slide", //展開的時候 顯示的動畫效果
  73. hide:"slide",//關閉窗體時的效果 有toggle slide
  74. modal:true, //ture是遮罩的效果 ,默認的是fasle
  75. position:"top",//彈出的對話框彈出的位置 topleft,rigth,right
  76. title:"添加老王", //設置對話框的標題
  77. open:function(event,ui){
  78. alert("打開的時候觸發的事件");
  79. }
  80. });
  81. //添加事件
  82. $("#dialog_link,").hover(function(){
  83. $(this).addClass("ui-state-hover");
  84. },function(){
  85. $(this).removeClass("ui-state-hover");
  86. });
  87. });
  88. </script>
  89. </head>
  90. <body>
  91. <p>
  92. <a href="#" id="dialog_link" class="ui-state-default ui-corner-all"><span
  93. class="ui-icon ui-icon-newwin"></span>Open Dialog</a>
  94. </p>
  95. <div id="dialog" title="Dialog Title">
  96. <p>
  97. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
  98. eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
  99. ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
  100. aliquip ex ea commodo consequat.
  101. </p>
  102. </div>
  103. </body>
  104. </html>
  105. 注:遮罩效果使用的屬性為:modal:true,
Copyright © Linux教程網 All Rights Reserved