jQuery Mobile - 單選框垂直組部件



說明

在欄位集中設定 data-role = "controlgroup" 屬性後,多個單選框會整合到該組內。框架會自動將底部和頂部拐角處的圓角設為圓形,並刪除所有邊距。預設情況下,單選框會垂直設定。

示例

以下示例演示了在 jQuery Mobile 中使用垂直單選框

<!DOCTYPE html>
<html>
   <head>
      <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>
         <h2>Radio Vertical Group Example</h2>
         <fieldset data-role = "controlgroup">
            <input type = "radio" id = "radio1" name = "radio-choice-0" checked = "checked" />
            <label for = "radio1">Radio 1</label>

            <input type = "radio" id = "radio2" name = "radio-choice-0" />
            <label for = "radio2">Radio 2</label>

            <input type = "radio" id = "radio3" name = "radio-choice-0" />
            <label for = "radio3">Radio 3</label>
         </fieldset>
      </form>
   </body>
</html>

輸出

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

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

  • 以https:///radio_vertical_group.html 的形式開啟該 HTML 檔案,以下輸出即會顯示。

jquery_mobile_widgets.htm
廣告
© . All rights reserved.