- Foundation 教程
- Foundation - 首頁
- Foundation - 概述
- Foundation - 安裝
- Foundation - 入門專案
- Foundation - Kitchen Sink
- Foundation 通用
- Foundation - 全域性樣式
- Foundation - Sass
- Foundation - JavaScript
- Foundation - JavaScript 實用程式
- Foundation - 媒體查詢
- Foundation - 網格
- Foundation - 彈性網格
- Foundation - 表單
- Foundation - 可見性類
- Foundation - 基本排版
- Foundation - 排版幫助程式
- Foundation - 基本控制元件
- Foundation - 導航
- Foundation - 容器
- Foundation - 媒體
- Foundation - 外掛
- Foundation SASS
- Foundation - Sass 函式
- Foundation - Sass Mixin
- Foundation 庫
- Foundation - Motion UI
- Foundation 有用資源
- Foundation - 快速指南
- Foundation - 有用資源
- Foundation - 討論
Foundation - 複選框和單選框
描述
複選框可用於從列表中選擇多個選項;單選框只能用於選擇一個選項。
將一組複選框和單選框封閉在 fieldset 元素中,並使用 legend 元素為它們提供一個公用文字。
fieldset 元素中的每個控制元件都必須有單獨的標籤,可以使用 label 標籤建立。
範例
以下示例演示在 Foundation 中使用 複選框和單選框。
<html>
<head>
<title>Checkboxes and Radio Buttons</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/css/foundation.min.css" crossorigin="anonymous">
<!-- Compressed JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/vendor/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/js/foundation.min.js" crossorigin="anonymous"></script>
</head>
<body>
<form>
<div class = "row">
<fieldset class = "medium-12 columns">
<legend>Select your vehicle</legend>
<input type = "radio" name = "vehicle" value = "XUV" id = "vehicleXUV" required>
<label for = "vehicleXUV">XUV</label>
<input type = "radio" name = "vehicle" value = "XYLO" id = "vehicleXYLO">
<label for = "vehicleXYLO">XYLO</label>
<input type = "radio" name = "vehicle" value = "SCORPIO" id = "vehicleSCORPIO">
<label for = "vehicleSCORPIO">SCORPIO</label>
</fieldset>
</div>
<div class = "row">
<fieldset class = "medium-12 columns">
<legend>Choose your favourite company</legend>
<input id = "audi" type = "checkbox">
<label for = "audi">Audi</label>
<input id = "mahindra" type = "checkbox">
<label for = "mahindra">Mahindra</label>
<input id = "benz" type = "checkbox">
<label for = "benz">Benz</label>
</fieldset>
</div>
</form>
<script>
$(document).ready(function() {
$(document).foundation();
})
</script>
</body>
</html>
輸出
讓我們執行以下步驟,看看上面給出的程式碼如何工作 -
將上面給出的 html 程式碼儲存為 forms_check_radio.html 檔案。
在瀏覽器中開啟此 HTML 檔案,將顯示如下所示的輸出。
foundation_forms.htm
廣告