单选框其实很简单,只需要两个主要属性定义就好,看效果图:
代码如下:
<!DOCTYPE html>
<html>
<head>
<title>form表单</title>
</head>
<body>
<form action="http://www.crazy.org" method="get">
第一组单选框:<br>
红:<input type="radio" name="color" id="color" value="red"/><br>
绿:<input type="radio" name="color" id="color2" value="green"/><br>
蓝:<input type="radio" name="color" id="color3" value="blue"/><br>
第二组单选框:<br>
男性:<input type="radio" name="gander" id="gander" value="male"><br>
<!-- name:形成参数列表,name值设置成一样时,实现单选;name和value是标配,一般情况下默认都加上 -->
女性:<input type="radio" name="gander" id="gander2" value="female"><br>
</form>
</body>
</html>
type="radio"这句设置输入框是选择框,一组选择框的name值一致时,才能达到单选的效果,如上代码,两组name值不同,则会形成两个不同的参数列表。