HTML基础教程之表单中单选按钮和复选按钮

单选按钮

 语法格式:<input  type = “radio”  属性 = “值”  />

常用属性

  •  Name:元素的名称

  • Value:元素的值,该value中数据将发往服务器。

  •  Checked:默认选择哪一项。如:checked = “checked”

注意:一组单选按钮,只能选择一个,但name的值必须一致。如:name = “sex”

      单选按钮用户自己不能输入内容,用户只能选择,因此必须为它指默认值value。


复选框

 语法格式:<input  type = “checkbox”  属性 = “值”  />

常用属性

  • Name:元素的名称

  • Value:元素的值

  • Checked:默认选中。如:checked = “checked”

注意:复选框也是一组选项,因此name的值必须一致。在PHP中,使用数组来获取多个同名的name的值。

      复选框可以同时选多个,也可以一个都不选。

来丰富我们的第一个例子吧

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>用户注册</title>
    </head>
    <body>
        <font size="5" color="red">欢迎注册php.cn</font>
        <form name="user" method="get" action="" >
            用户名:<input type="text" name="username"/>
            <br/>
            密码:<input type="password" name="userpwd"/>
            <br/>
            性别:<input type="radio" name="sex" value="男" checked=checked>男
            <input type="radio" name="sex" value="女">女
            <br/>
            爱好:<input type="checkbox" name="hobby" value="运动">运动
            <input type="checkbox" name="hobby" value="看电影">看电影
            <input type="checkbox" name="hobby" value="编程" checked="checked">编程
            <input type="checkbox" name="hobby" value="宅着">宅着
            <br/><input type="submit" value="提交信息"/>
        </form>
    </body>

是不是内容多了点,接着下一节,继续加吧


继续学习
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<font size="5" color="red">php.cn</font>
<form name="user" method="get" action="" >
<input type="text" name="username"/>
<br/>
<input type="password" name="userpwd"/>
<br/>
<input type="radio" name="sex" value="" checked=checked>
<input type="radio" name="sex" value="">
<br/>
<input type="checkbox" name="hobby" value="">
<input type="checkbox" name="hobby" value="">
<input type="checkbox" name="hobby" value="" checked="checked">
<input type="checkbox" name="hobby" value="">
<br/><input type="submit" value=""/>
</form>
</body>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
提交重置代码
图片放大关闭