<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      jquery ui中的dialog,官網上經典的例子

      jquery ui中dialog和easy ui中的dialog很像,但是最近用到的時候全然沒有印象,一段時間不用就忘記了,這篇隨筆介紹一下這個控件。

      1.實例

      官網源代碼中給出了一些實例,首先看看實例是什么樣子的。

       

      a.默認功能

      也是最簡單的應用,也就是打開一個對話框,代碼如下

      <!doctype html>
      <html lang="en">
      <head>
          <meta charset="utf-8">
          <title>jQuery UI Dialog - Default functionality</title>
          <link rel="stylesheet" href="../../themes/base/all.css">
          <script src="../../external/jquery/jquery.js"></script>
          <script src="../../ui/core.js"></script>
          <script src="../../ui/widget.js"></script>
          <script src="../../ui/mouse.js"></script>
          <script src="../../ui/draggable.js"></script>
          <script src="../../ui/position.js"></script>
          <script src="../../ui/resizable.js"></script>
          <script src="../../ui/button.js"></script>
          <script src="../../ui/dialog.js"></script>
          <link rel="stylesheet" href="../demos.css">
          <script>
          $(function() {
              $( "#dialog" ).dialog();
          });
          </script>
      </head>
      <body>
      
      <div id="dialog" title="Basic dialog">
          <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
      </div>
      
      <div class="demo-description">
      <p>The basic dialog window is an overlay positioned within the viewport and is protected from page content (like select elements) shining through with an iframe.  It has a title bar and a content area, and can be moved, resized and closed with the 'x' icon by default.</p>
      </div>
      </body>
      </html>

      引用了一堆的js文件,這個與下載的時候選擇的類型有關,可以選擇All jQuery UI Downloads,也可以在當前頁面選擇要用到的組件下載。關鍵代碼$( "#dialog" ).dialog();,加載頁面的時候彈出一個對話框。效果如下圖1


      圖1

       

      b.模態對話框

      關鍵代碼如下:

          $(function() {
              $( "#dialog-message" ).dialog({
                  modal: true,
                  buttons: {
                      Ok: function() {
                          $( this ).dialog( "close" );
                      }
                  }
              });
          });

      作用是彈出一個模態對話框,mode:true,其實就是后面不能回到后面的父頁面,除非關閉當前的對話框。在對話框后面加了一個OK關閉按鈕,效果如下圖2


      圖2

       

      c.確認對話框

      關鍵代碼如下:

          $(function() {
              $( "#dialog-confirm" ).dialog({
                  resizable: false,
                  height: "auto",
                  width: 400,
                  modal: true,
                  buttons: {
                      "Delete all items": function() {
                  //這里可以加入一些操作 $(
      this ).dialog( "close" ); }, Cancel: function() { $( this ).dialog( "close" ); } } }); });

      加了兩個按鈕,一個確認,一個取消,可以分別做一些操作,其實也不限于這兩個按鈕,如果需要的話可以在下面添加任意多個按鈕,實現任意多的功能。效果如下如3


      圖3

      帶form功能的對話框

      這個例子有些復雜,可以實現驗證,請求等功能,關鍵代碼如下

      <!doctype html>
      <html lang="en">
      <head>
          <meta charset="utf-8">
          <title>jQuery UI Dialog - Modal form</title>
          <link rel="stylesheet" href="../../themes/base/all.css">
          <script src="../../external/jquery/jquery.js"></script>
          <script src="../../ui/core.js"></script>
          <script src="../../ui/widget.js"></script>
          <script src="../../ui/mouse.js"></script>
          <script src="../../ui/button.js"></script>
          <script src="../../ui/draggable.js"></script>
          <script src="../../ui/position.js"></script>
          <script src="../../ui/resizable.js"></script>
          <script src="../../ui/dialog.js"></script>
          <script src="../../ui/effect.js"></script>
          <link rel="stylesheet" href="../demos.css">
          <style>
              label, input { display:block; }
              input.text { margin-bottom:12px; width:95%; padding: .4em; }
              fieldset { padding:0; border:0; margin-top:25px; }
              h1 { font-size: 1.2em; margin: .6em 0; }
              div#users-contain { width: 350px; margin: 20px 0; }
              div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
              div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
              .ui-dialog .ui-state-error { padding: .3em; }
              .validateTips { border: 1px solid transparent; padding: 0.3em; }
          </style>
          <script>
          $(function() {
              var dialog, form,
      
                  // From http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29
                  emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
                  name = $( "#name" ),
                  email = $( "#email" ),
                  password = $( "#password" ),
                  allFields = $( [] ).add( name ).add( email ).add( password ),
                  tips = $( ".validateTips" );
      
              function updateTips( t ) {
                  tips
                      .text( t )
                      .addClass( "ui-state-highlight" );
                  setTimeout(function() {
                      tips.removeClass( "ui-state-highlight", 1500 );
                  }, 500 );
              }
      
              function checkLength( o, n, min, max ) {
                  if ( o.val().length > max || o.val().length < min ) {
                      o.addClass( "ui-state-error" );
                      updateTips( "Length of " + n + " must be between " +
                          min + " and " + max + "." );
                      return false;
                  } else {
                      return true;
                  }
              }
      
              function checkRegexp( o, regexp, n ) {
                  if ( !( regexp.test( o.val() ) ) ) {
                      o.addClass( "ui-state-error" );
                      updateTips( n );
                      return false;
                  } else {
                      return true;
                  }
              }
      
              function addUser() {
                  var valid = true;
                  allFields.removeClass( "ui-state-error" );
      
                  valid = valid && checkLength( name, "username", 3, 16 );
                  valid = valid && checkLength( email, "email", 6, 80 );
                  valid = valid && checkLength( password, "password", 5, 16 );
      
                  valid = valid && checkRegexp( name, /^[a-z]([0-9a-z_\s])+$/i, "Username may consist of a-z, 0-9, underscores, spaces and must begin with a letter." );
                  valid = valid && checkRegexp( email, emailRegex, "eg. ui@jquery.com" );
                  valid = valid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
      
                  if ( valid ) {
                      $( "#users tbody" ).append( "<tr>" +
                          "<td>" + name.val() + "</td>" +
                          "<td>" + email.val() + "</td>" +
                          "<td>" + password.val() + "</td>" +
                      "</tr>" );
                      dialog.dialog( "close" );
                  }
                  return valid;
              }
      
              dialog = $( "#dialog-form" ).dialog({
                  autoOpen: false,
                  height: 400,
                  width: 350,
                  modal: true,
                  buttons: {
                      "Create an account": addUser,
                      Cancel: function() {
                          dialog.dialog( "close" );
                      }
                  },
                  close: function() {
                      form[ 0 ].reset();
                      allFields.removeClass( "ui-state-error" );
                  }
              });
      
              form = dialog.find( "form" ).on( "submit", function( event ) {
                  event.preventDefault();
                  addUser();
              });
      
              $( "#create-user" ).button().on( "click", function() {
                  dialog.dialog( "open" );
              });
          });
          </script>
      </head>
      <body>
      
      <div id="dialog-form" title="Create new user">
          <p class="validateTips">All form fields are required.</p>
      
          <form>
              <fieldset>
                  <label for="name">Name</label>
                  <input type="text" name="name" id="name" value="Jane Smith" class="text ui-widget-content ui-corner-all">
                  <label for="email">Email</label>
                  <input type="text" name="email" id="email" value="jane@smith.com" class="text ui-widget-content ui-corner-all">
                  <label for="password">Password</label>
                  <input type="password" name="password" id="password" value="xxxxxxx" class="text ui-widget-content ui-corner-all">
      
                  <!-- Allow form submission with keyboard without duplicating the dialog button -->
                  <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
              </fieldset>
          </form>
      </div>
      
      
      <div id="users-contain" class="ui-widget">
          <h1>Existing Users:</h1>
          <table id="users" class="ui-widget ui-widget-content">
              <thead>
                  <tr class="ui-widget-header ">
                      <th>Name</th>
                      <th>Email</th>
                      <th>Password</th>
                  </tr>
              </thead>
              <tbody>
                  <tr>
                      <td>John Doe</td>
                      <td>john.doe@example.com</td>
                      <td>johndoe1</td>
                  </tr>
              </tbody>
          </table>
      </div>
      <button id="create-user">Create new user</button>
      
      <div class="demo-description">
      <p>Use a modal dialog to require that the user enter data during a multi-step process.  Embed form markup in the content area, set the <code>modal</code> option to true, and specify primary and secondary user actions with the <code>buttons</code> option.</p>
      </div>
      </body>
      </html>

      這個是帶請求功能的對話框,代碼很嚴謹

      var dialog, form,
      emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
      name = $( "#name" ),
      email = $( "#email" ),
      password = $( "#password" ),
      allFields = $( [] ).add( name ).add( email ).add( password ),
      tips = $( ".validateTips" );

      定義元素變量,要用到的驗證,allFields = $( [] ).add( name ).add( email ).add( password ),這個用來把要用到的變量加到集合里面,用來添加和刪除css樣式,后面會用到的,很巧妙,$( [] )這個寫法可以把多個元素添加到一個集合中。

      function updateTips( t ) {
      tips
      .text( t )
      .addClass( "ui-state-highlight" );
      setTimeout(function() {
      tips.removeClass( "ui-state-highlight", 1500 );
      }, 500 );
      }

      給元素添加文字和css樣式,并且在500毫秒內移除這個樣式,不明白.removeClass( "ui-state-highlight", 1500 )后面一個參數1500是什么意思

      function checkLength( o, n, min, max ) {
      if ( o.val().length > max || o.val().length < min ) {
      o.addClass( "ui-state-error" );
      updateTips( "Length of " + n + " must be between " +
      min + " and " + max + "." );
      return false;
      } else {
      return true;
      }
      }

      檢查輸入文字的長短,4個參數分別是元素本身,元素名稱,最小長度,最大長度。

      function checkRegexp( o, regexp, n ) {
      if ( !( regexp.test( o.val() ) ) ) {
      o.addClass( "ui-state-error" );
      updateTips( n );
      return false;
      } else {
      return true;
      }
      }

      用正則表達式檢查元素是否符合規則,3個參數,元素本身,正則表達式,錯誤提示。

      function addUser() {
      var valid = true;
      allFields.removeClass( "ui-state-error" );

      valid = valid && checkLength( name, "username", 3, 16 );
      valid = valid && checkLength( email, "email", 6, 80 );
      valid = valid && checkLength( password, "password", 5, 16 );

      valid = valid && checkRegexp( name, /^[a-z]([0-9a-z_\s])+$/i, "Username may consist of a-z, 0-9, underscores, spaces and must begin with a letter." );
      valid = valid && checkRegexp( email, emailRegex, "eg. ui@jquery.com" );
      valid = valid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

      if ( valid ) {
      $( "#users tbody" ).append( "<tr>" +
      "<td>" + name.val() + "</td>" +
      "<td>" + email.val() + "</td>" +
      "<td>" + password.val() + "</td>" +
      "</tr>" );
      dialog.dialog( "close" );
      }
      return valid;
      }

      添加用戶的方法,驗證方法valid = valid && 這個用的很巧妙,連續利用了&&操作,這里的寫法非常的靈活也很巧妙。在這里可以實現具體的功能,也可以在form里面添加action,form到具體頁面中操作。

      dialog = $( "#dialog-form" ).dialog({
      autoOpen: false,
      height: 400,
      width: 350,
      modal: true,
      buttons: {
      "Create an account": addUser,
      Cancel: function() {
      dialog.dialog( "close" );
      }
      },
      close: function() {
      form[ 0 ].reset();
      allFields.removeClass( "ui-state-error" );
      }
      });

      這里才是最主要的功能,一個定義一個對話框,其中有個2個按鈕,一個是添加一個賬號,訪問addUser函數,一個是取消,直接定義關閉對話框,最后還定義了默認的關閉功能,form中清除元素的值,清除錯誤提示。

      form = dialog.find( "form" ).on( "submit", function( event ) {
      event.preventDefault();
      addUser();
      });

      定義form,其實就是頁面中的form,還定義了提交時請求動作,首先取消默認事件,然后執行addUser。

      $( "#create-user" ).button().on( "click", function() {
      dialog.dialog( "open" );
      });

      給添加用戶按鈕綁定事件,這里綁定事件沒有直接.click,也沒有live,也沒有trigger,on是jquery官方推薦的一個綁定函數方法。注意這里不是頁面加載的時候就顯示對話框,而是點擊添加賬號的時候彈出這個對話框,所以要先定義這個對話框“dialog = $( "#dialog-form" ).dialog({”,點擊添加按鈕的時候彈出對話框“dialog.dialog( "open" );”。

      頁面截圖如下圖4


      圖4

      點擊添加用戶彈出對話框如圖5


      圖5

      元素驗證失敗時截圖如圖6


      圖6

      這個例子很經典!

      d.帶動畫功能的對話框

      關鍵代碼如下:

          $(function() {
              $( "#dialog" ).dialog({
                  autoOpen: false,
                  show: {
                      effect: "blind",
                      duration: 1000
                  },
                  hide: {
                      effect: "explode",
                      duration: 1000
                  }
              });
      
              $( "#opener" ).click(function() {
                  $( "#dialog" ).dialog( "open" );
              });
          });

      定義顯示和影藏效果,effect: "blind":打開時時百葉窗效果,從上到下顯示,effect: "explode"關閉時是爆發,碎片效果。

      百葉窗效果如下圖7


      圖7

      爆炸效果如圖8


      圖8

      同上,注意這里不是頁面加載的時候就顯示對話框,而是點擊添加賬號的時候彈出這個對話框,所以要先定義這個對話框“$( "#dialog" ).dialog({,”,點擊添加按鈕的時候彈出對話框“dialog.dialog( "open" );”

       

      2.屬性,事件,方法

      關于屬性,事件和方法內容很多,可以查看中文文檔http://jqueryui.net/dialog/

       

      posted @ 2014-12-27 18:34  nd  閱讀(87222)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产精品SM捆绑调教视频| 92国产精品午夜福利免费| 新龙县| 亚洲avav天堂av在线网爱情| 国产亚洲精品久久久久婷婷瑜伽 | 久播影院无码中文字幕| 天堂一区二区三区av| 日韩人妻无码一区二区三区99| 98精品全国免费观看视频| 国产午夜精品理论大片| 国产成人一区二区免av| 国产AV老师黑色丝袜美腿| 亚洲国产成人片在线观看无码 | 亚洲天堂av在线一区| 99在线精品视频观看免费| 四虎成人精品无码| 国产精品一区二区三区黄| 中文字幕亚洲资源网久久| 2020国产成人精品视频| 亚洲偷自拍国综合| 亚洲国产一区二区av| 国产不卡精品视频男人的天堂 | 丰原市| 欧洲美熟女乱又伦免费视频| 国产熟女丝袜av一二区| 9久久伊人精品综合| 亚洲精品日韩精品久久| 特黄做受又粗又大又硬老头| 国产不卡一区二区精品| 亚洲精品国产精品国自产| 久久大香线蕉国产精品免费| 国产精品一区在线免费看| 性色av无码久久一区二区三区| 一区二区三区激情都市| 国产性生大片免费观看性| 元码人妻精品一区二区三区9| 亚洲av永久无码精品漫画| 国产女人在线视频| 亚洲va久久久噜噜噜久久狠狠| 国产精品中文字幕自拍| 微拍福利一区二区三区|