前端HTMLform表单标签input标签type属性radio单选框
<input type="radio"> 单选框
适⽤于选择性别按钮⽹页等
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
</head>
<body>
<div>
<form>
<div>
<!-- 单选框 -->
<input type="radio">
</div>
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
</head>
<body>
<form action="www.baidu" method="get">
<div>
<p>
请选择性别:
男<input type="radio">
⼥<input type="radio">
</p>
</div>
<input type="submit" value="提交">
</form>
</body>
</html>
设置checked属性默认选中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
</head>
<body>
<form action="www.baidu" method="get">
<div>
<!-- checked被默认选中 -->
<p>
请选择性别:
男<input type="radio" checked>
⼥<input type="radio">
</p>
</div>
<input type="submit" value="提交">
</form>
</body>
html radio点击变颜
</html>
提交到后台时候选中⼀个提交⼀个就可以了⽤value区分提交哪个把value提交就可以了
input type=‘radio’ - 单选框 value,name属性(产⽣互斥效果:name要相等)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
</head>
<body>
<form action="www.baidu" method="get">
<div>
<!-- 产⽣互斥效果:name要相同-->
<p>
请选择性别:
男<input type="radio" name="gender" value="1" checked>
⼥<input type="radio" name="gender" value="2">
</p>
</div>
<input type="submit" value="提交">
</form>
</body>
</html>
点击提交
url上显⽰gender=1 就是男
提交
gender=2 ⼥的
key-value形式
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论