HTML5入门 之 单选按钮
2025-01-29
前言
在上一表单程序中继续添加单选按钮操作
参考视频:
1.黑马程序员5天软件测试从入门到精通_软件测试基础教程
1.写入程序
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!-- 所有要填写的内容都要放在form标签中
action 代表数据给哪个个后台程序
method 代表输入数据的方法 1、post(加密) 2、get(不加密)
-->
<form action="" method="POST">
<!-- input 代表输入框标签(单标签),
type 类型决定这个输入的类型,
name 属性代表这个输入框的名字,
id 打包输入框的id 编号
value 代表默认输入框的值 -->
<!-- nicheng:<input type="text" name="hha" id="hhee" value="hahaha"/> -->
昵称: <input type="text" name="hha" id="hhee" placeholder="hahha"/>
<!-- placeholder 属于ie低版本不兼容,但是不会造成页面的混乱,认为此属性没问题 -->
<br />
<!-- input 的type 类型是password 代表密码筐,用户输入的文字会加密 -->
密码: <input type="password" /> <br />
性别: <input type="radio" name="xb" id="nan" checked=checked /><label for="nan">男</label>
<input type="radio" name="xb" id="nv"/> <label for="nv">女 </label>
<input type="radio" name="xb" id="baomi"/> <label for="baomi"> 保密</label> <br />
</form>
</body>
</html>
2.页面展示
3.
- type= “radio"
- 注意:如果想让文字点击能切换按钮,那要加label 标签,并且设置for 属性和对应的单选按钮的id 属性值一致
- 必须给这一组单选按钮添加那name 值,才可以实现单选效果
- 设置默认选中状态,要到单选按钮中添加checked=“checked”