jQuery Mobile - Controlgroup 複選框



說明

你可以使用 type = "checkbox" 屬性在 controlgroup 中建立複選框。

示例

下列示例描述了在 jQuery Mobile Framework 中使用 controlgroup 複選框 的情況。

<!DOCTYPE html>
<html>
   <head>
      <title>Controlgroup Checkbox</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>
      <h2>Vertical Checkbox</h2>
      <form>
         <fieldset data-role = "controlgroup">
            <input type = "checkbox" name = "checkbox1" id = "checkbox11" />
            <label for = "checkbox11">India</label>
            
            <input type = "checkbox" name = "checkbox1" id = "checkbox12" />
            <label for = "checkbox12">Australia</label>
            
            <input type = "checkbox" name = "checkbox1" id = "checkbox13" />
            <label for = "checkbox13">New Zealand</label>
         </fieldset>
      </form>
      
      <h2>Minisized Vertical Checkbox</h2>
      <form>
         <fieldset data-role = "controlgroup" data-mini = "true">
            <input type = "checkbox" name = "checkbox1" id = "checkbox14" />
            <label for = "checkbox14">India</label>
            
            <input type = "checkbox" name = "checkbox1" id = "checkbox15" />
            <label for = "checkbox15">Australia</label>
            
            <input type = "checkbox" name = "checkbox1" id = "checkbox16" />
            <label for = "checkbox16">New Zealand</label>
         </fieldset>
      </form>
      
      <h2>Horizontal Checkbox</h2>
      <form>
         <fieldset data-role = "controlgroup" data-type = "horizontal">
            <input type = "checkbox" name = "checkbox1" id = "checkbox17" />
            <label for = "checkbox17">India</label>
            
            <input type = "checkbox" name = "checkbox1" id = "checkbox18" />
            <label for = "checkbox18">Australia</label>
            
            <input type = "checkbox" name = "checkbox1" id = "checkbox19" />
            <label for = "checkbox19">New Zealand</label>
         </fieldset>
      </form>
      
      <h2>Minisized Horizontal Checkbox</h2>
      <form>
         <fieldset data-role = "controlgroup" data-type = "horizontal" data-mini = "true">
            <input type = "checkbox" name = "radio1" id = "checkbox20" />
            <label for = "checkbox20">India</label>
            
            <input type = "checkbox" name = "radio1" id = "checkbox21" />
            <label for = "checkbox21">Australia</label>
            
            <input type = "checkbox" name = "radio1" id = "checkbox22" />
            <label for = "checkbox22">New Zealand</label>
         </fieldset>
      </form>
      
   </body>
</html>

輸出

讓我們按照下列步驟來看看上面的程式碼是如何工作的 -

  • 將以上的 html 程式碼另存為 jqm_controlgroup_checkbox.html 檔案,並儲存在伺服器根目錄下。

  • 將此 HTML 檔案作為 https:///jqm_controlgroup_checkbox.html 開啟,將會顯示以下輸出。

jquery_mobile_widgets.htm
廣告
© . All rights reserved.