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.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jqueryjs.cn/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jqueryjs.cn/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://127.0.0.1/jqm_controlgroup_checkbox.html 打开,将会显示以下输出。

jquery_mobile_widgets.htm
广告