jQuery Mobile - 單選按鈕組



描述

你可以使用 data-role = "controlgroup" 屬性在單選按鈕組中顯示單選按鈕。

示例

以下示例描述了在 jQuery Mobile 框架中使用 *單選按鈕組*。

<!DOCTYPE html>
<html>
   <head>
      <title>Controlgroup Radio Button</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 Radio Button</h2>
      <form>
         <fieldset data-role = "controlgroup">
            <input type = "radio" name = "radio1" id = "radio11" value = "val1" 
               checked = "checked" />
            <label for = "radio11">India</label>
            
            <input type = "radio" name = "radio1" id = "radio12" value = "val2" />
            <label for = "radio12">Australia</label>
            
            <input type = "radio" name = "radio1" id = "radio13" value = "val3" />
            <label for = "radio13">New Zealand</label>
         </fieldset>
      </form>
      
      <br><br>
      <h2>Minisized Vertical Radio Button</h2>
      <form>
         <fieldset data-role = "controlgroup" data-mini = "true">
            <input type = "radio" name = "radio1" id = "radio14" value = "val1" 
               checked = "checked" />
            <label for = "radio14">India</label>
            
            <input type = "radio" name = "radio1" id = "radio15" value = "val2" />
            <label for = "radio15">Australia</label>
            
            <input type = "radio" name = "radio1" id = "radio16" value = "val3" />
            <label for = "radio16">New Zealand</label>
         </fieldset>
      </form>
      
      <h2>Horizontal Radio Button</h2>
      <form>
         <fieldset data-role = "controlgroup" data-type = "horizontal">
            <input type = "radio" name = "radio1" id = "radio17" value = "val1" 
               checked = "checked" />
            <label for = "radio17">India</label>
            
            <input type = "radio" name = "radio1" id = "radio18" value = "val2" />
            <label for = "radio18">Australia</label>
            
            <input type = "radio" name = "radio1" id = "radio19" value = "val3" />
            <label for = "radio19">New Zealand</label>
         </fieldset>
      </form>
      <br><br>
      
      <h2>Minisized Horizontal Radio Button</h2>
      <form>
         <fieldset data-role = "controlgroup" data-type = "horizontal" data-mini = "true">
            <input type = "radio" name = "radio1" id = "radio20" value = "val1" 
               checked = "checked" />
            <label for = "radio20">India</label>
            
            <input type = "radio" name = "radio1" id = "radio21" value = "val2" />
            <label for = "radio21">Australia</label>
            
            <input type = "radio" name = "radio1" id = "radio22" value = "val3" />
            <label for = "radio22">New Zealand</label>
         </fieldset>
      </form>
      
   </body>
</html>

輸出

讓我們執行以下步驟以瞭解以上程式碼如何執行 -

  • 將以上 HTML 程式碼另存為伺服器根資料夾中的 jqm_controlgroup_radio_button.html 檔案。

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

jquery_mobile_widgets.htm
廣告
© . All rights reserved.