示例工程 26-select-radio-checkbox
26-select-radio-checkbox/demo-01-radio-checkbox/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>单选与多选演示</title>
<style>
body { margin: 0; padding: 32px; background: #f8fafc; color: #0f172a; font-family: system-ui, sans-serif; line-height: 1.7; }
.box { max-width: 720px; margin-bottom: 16px; padding: 18px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; }
h1 { margin: 0 0 16px; font-size: 28px; }
h2 { margin: 0 0 8px; font-size: 17px; }
p { margin: 0 0 10px; color: #334155; }
fieldset { margin: 0 0 12px; padding: 10px; border: 1px solid #e2e8f0; border-radius: 8px; }
legend { padding: 0 6px; color: #475569; font-size: 13px; }
label { display: inline-flex; align-items: center; gap: 6px; margin: 4px 14px 4px 0; font-size: 14px; }
input { width: auto; }
pre { margin: 8px 0 0; padding: 10px; overflow-x: auto; border-radius: 8px; background: #0f172a; color: #e2e8f0; font-size: 12px; }
</style>
</head>
<body>
<h1>单选与多选</h1>
<div class="box">
<h2>单选组</h2>
<form action="preview.html" method="get">
<fieldset>
<legend>结算周期</legend>
<label><input type="radio" name="cycle" value="monthly" checked /> 按月</label>
<label><input type="radio" name="cycle" value="yearly" /> 按年</label>
</fieldset>
</form>
<p>同名 radio 互斥,checked 指定默认项。</p>
</div>
<div class="box">
<h2>多选组</h2>
<form action="preview.html" method="get">
<fieldset>
<legend>通知方式</legend>
<label><input type="checkbox" name="notify" value="email" checked /> 邮件</label>
<label><input type="checkbox" name="notify" value="sms" /> 短信</label>
<label><input type="checkbox" name="notify" value="webhook" /> Webhook</label>
</fieldset>
</form>
<p>同名 checkbox 提交多个值:<code>notify=email&notify=sms</code>。</p>
</div>
</body>
</html>