jQuery Mobile - 對照組篩選器



說明

對照組按鈕還可以使用 data-filter 屬性對元素進行篩選,該屬性建立對照組。你還可以根據 data-filtertext 屬性中宣告的文字字串篩選元素。

示例

以下示例展示了在 jQuery Mobile 中使用 可篩選對照組

<!DOCTYPE html>
<html>
   <head>
      <title>Filterable controlgroup</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>

   <body>
      <form>
         <input data-type = "search" id = "filterControlgroup-input">
      </form>
      
      <div data-role = "controlgroup" data-filter = "true" 
         data-input = "#filterControlgroup-input">
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all">Button 1</a>
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all" 
            data-filtertext = "two">Button 2</a>
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all" 
            data-filtertext = "three">Button 3</a>
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all">Button 4</a>
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all">Button 5</a>
      </div>
      
   </body>
</html>

輸出

讓我們執行以下步驟,瞭解上面的程式碼如何工作 -

  • 將上述 html 程式碼另存為filterable_controlgroup.html 檔案,並將其儲存在伺服器的根資料夾中。

  • 將此 HTML 檔案開啟為 https:///filterable_controlgroup.html,即可顯示以下輸出。

jquery_mobile_widgets.htm
廣告
© . All rights reserved.