html网页制作表单
时间: 2023-12-09 13:35:13 浏览: 28
HTML是一种用于创建网页的标记语言,表单是HTML中的一种重要元素,可以用于收集用户输入的数据。以下是一个简单的HTML表单的例子:
```html
<form action="/submit-form" method="post">
<label for="name">姓名:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">邮箱:</label>
<input type="email" id="email" name="email"><br><br>
<label for="gender">性别:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">男</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">女</label><br><br>
<label for="age">年龄:</label>
<select id="age" name="age">
<option value="18">18岁以下</option>
<option value="18-30">18-30岁</option>
<option value="30-50">30-50岁</option>
<option value="50+">50岁以上</option>
</select><br><br>
<label for="comment">评论:</label><br>
<textarea id="comment" name="comment" rows="5" cols="40"></textarea><br><br>
<input type="submit" value="提交">
</form>
```
上述代码中,`<form>`标签表示一个表单,`action`属性指定了表单提交的URL,`method`属性指定了表单提交的方式(GET或POST)。`<label>`标签用于描述表单控件,`for`属性指定了与之关联的控件的`id`,`<input>`标签用于创建各种表单控件,例如文本框、单选框、复选框等,`type`属性指定了控件的类型,`name`属性指定了控件的名称,`value`属性指定了控件的值,`<select>`标签用于创建下拉列表,`<option>`标签用于创建下拉列表中的选项,`<textarea>`标签用于创建多行文本框,`rows`和`cols`属性指定了文本框的行数和列数,`<input type="submit">`用于创建提交按钮。