【html学习笔记】3.表单元素

1.文本框

1.1 语法

<input type = "text">表示文本框。且只能写一行

1.2 属性

  1. 使用属性size 设置文本框大小

  1. 使用属性value 来设置文本框的默认文字

    复制代码
      <input type="text" size="30" value = "显示在文本框里的初始值">
  1. 使用属性placeholder来设置文本框的背景文字

    复制代码
        <input type="text" size="30" placeholder = "请输入账号">

2.密码框

表示方法:

复制代码
<input type="password"> 

使用密码框时会自动将输入的内容转换为星号

3.表单

表单用于搜集不同类型的用户输入。

表单的表示方式是<form>

表单用于向服务器提交数据,比如用户名和密码等。

表示将数据提交到服务端的login.jsp里面了

复制代码
<form action="login.jsp">
账号:<input type="text" name="name"> <br/>
密码:<input type="password" name="password" > <br/>
<input type="submit" value="登陆">
</form>

提交数据的方式

<form>中提交数据的属性有两种,一种是 method="get" ,一种是method="post"

  • method="get"
    是默认的提交表单数据的方式。如果没有指定的话一般采用这种
    get方式可以在地址栏中看到提交的数据。即使是密码也可以看到

  • method="post"
    post提交表单需要指定
    而且使用 post提交表单时不会显示出密码

4.单选框

<input type = "radio">表示单选框

复制代码
<html>
  <body>
  	星期一<input type = "radio">
	星期二<input type = "radio">  
  	星期三<input type = "radio">
	星期四<input type = "radio">  
  	星期五<input type = "radio">
	星期六<input type = "radio">  
	星期日<input type = "radio">  
</body> 
</html>

默认选中

默认选中,需要增加属性checked="checked" 选项

复制代码
 	星期一<input type = "radio" checked="checked" >
 	星期二<input type = "radio">  
  	星期三<input type = "radio">
	星期四<input type = "radio">  
  	星期五<input type = "radio">
	星期六<input type = "radio">  
	星期日<input type = "radio">  

一堆中只能选中一个

单选框一次能选中好几个选项,如果想要在一堆单选框里只能选中一个的话,则需要进行分组。

分组需要增加一个属性name,表示一组数据即name属性相同。

此时就只能在name相同的属性里选择一个了。

复制代码
<html>
  <body>
  	星期一<input type = "radio" name = "week" checked="checked" >
	星期二<input type = "radio" name = "week">  
  	星期三<input type = "radio" name = "week">
	星期四<input type = "radio" name = "week">  
  	星期五<input type = "radio" name = "week" >
	星期六<input type = "radio" name = "week">  
	星期日<input type = "radio" name = "week">  
</body> 
</html>

5.复选框

复选框用<input type= "checkbox">表示

复制代码
  <body>
	<p>这个周哪几天需要上班?</p>
  	星期一<input type = "checkbox">
	星期二<input type = "checkbox" >  
  	星期三<input type = "checkbox" >
	星期四<input type = "checkbox" >  
  	星期五<input type = "checkbox" >
	星期六<input type = "checkbox" >  
	星期日<input type = "checkbox" >  
</body> 

6 下拉列表

在HTML中,下拉列表需要<select><option>两者配合使用

复制代码
         <select>
  	<option>星期一</option>
	<option>星期二</option>  
  	<option>星期三</option>
	<option>星期四</option>  
  	<option>星期五</option>
	<option>星期六</option>  
	<option>星期日</option>
         </select>

设置下拉列表的高度

在select后增加属性size
<select size = "7" ><size>

设置下拉列表可以多选

需要使用键盘上的shift键

在select后增加属性multiple
<select size = "7" multiple = "multiple"><size>

7.文本域

文本域用<textarea>表示

与文本框不同的是,文本域可以显示多行数据。

指定长度和宽度

<textarea>增加属性cols和rows

复制代码
<html>
  <body>
         <textarea cols = "30" , rows = "7">
  	星期一
	星期二  
  	星期三
	星期四  
  	星期五
	星期六  
	星期日
         </textarea>
</body> 
</html>

8.普通按钮

普通按钮的表示方式是<input type="button">

普通按钮不能提交表单

复制代码
         <input type="button" value = "普通按钮"> 

9.提交按钮

<input type = "submit">是提交按钮。可以把数据提交到服务器

复制代码
<form method="get" action="login.jsp">
账号:<input type="text" name="name"> <br/>
密码:<input type="password" name="password" > <br/>
<input type="submit" value="登陆">
</form>

10.重置按钮

<input type = "reset">是重置按钮。可以把文本框里的内容清空

复制代码
<form method="get" action="login.jsp">
账号:<input type="text" name="name"> <br/>
密码:<input type="password" name="password" > <br/>
<input type="submit" value="登陆">
<input type="reset" value="重置">
</form>

11.图像提交

<input type="image" > 是使用图像作为提交的表示方式

复制代码
<input type="image" src="picture.jpg">


12 按钮

<button></button>是按钮标签

按钮标签中可以是图片,也可以是文字。

在按钮标签中添加属性type="submit,那么按钮也具有提交表单的功能

button中是文字

复制代码
<button>登陆</button>

button 的图片属性

复制代码
<button>
	<img src="picture.jpg"/>登陆
</button>

button的type属性

复制代码
<form method="get" action="login.jsp">
账号:<input type="text" name="name"> <br/>
密码:<input type="password" name="password" > <br/>
<button type="submit">登陆</button>
</form>
相关推荐
ouynagda6 分钟前
iMX6ull Linux 嵌入式驱动开发笔记(LCD / ADXL345 / SPI 子系统)
linux·arm开发·驱动开发·笔记·嵌入式硬件
qq_2842740511 分钟前
信号分析·傅里叶级数与频谱(单边谱·双边谱·傅里叶变换)CSDN发布稿
笔记·学习·信号处理·傅里叶分析
xian_wwq12 分钟前
【学习笔记】pgvector 入门:用 PostgreSQL 直接实现向量检索-13
笔记·学习·postgresql
kmomo..17 分钟前
Linux SPI 驱动开发学习笔记:从框架到实战
linux·驱动开发·学习
程序猿乐锅24 分钟前
【从0-1学习Python | 第四篇】Python 字符串和元组
java·开发语言·笔记·后端·python·学习
damoluomu32 分钟前
SSG 的后台怎么补:Node.js 生态里的三条路(番外二)
javascript·css·typescript·node.js·html
li星野38 分钟前
【学习记录】DAP调试器电路原理图完全详解:从STM32最小系统到SWD调试接口
stm32·嵌入式硬件·学习
东鹏特饮39 分钟前
贪吃蛇小游戏html
前端·javascript·html
诸神缄默不语1 小时前
小春学习日刊 2026年第2期:2026.10.14
学习
qq_284274051 小时前
电气控制与PLC·HMI触摸屏组态与自动伸缩门控制系统 CSDN发布稿
笔记·学习·自动化