开始时间:2021-4-2
课程链接:HTML
B/S和C/S
B/S
Browser和Server
浏览器端和服务器端 前端/后端
- 优点:升级方便,只升级服务器端代码即可。维护成本低。
- 缺点:速度慢、体验不好、界面不炫酷
C/S
client / server
(客户端/服务器端的交互形式。)
- 缺点:升级麻烦,维护成本较高。
- 优点:速度快,体验好,界面炫酷。(娱乐型的系统多数是c/s架构的)
HTML
HTML: Hyper Text Markup Language(超文本标记语言)
由大量的标签组成,每一个标签都有开始标签和结束标签。标签不区分大小写
超文本:流媒体、图片、声音、视频…
W3C:世界万维网联盟指定的规范
W3School可以作为参考手册
简单的程序
<html>
<head>
<title>网页标题</title>
</head>
<body>
网页的主体
</body>
</html>
不区分大小写,语法松散不严格
<!doctype html>
<html>
<head>
<title>网页标题</title>
</head>
<body>
<!--段落标记-->
<p> 床前明月光,疑是地上霜。
举头望明月,低头思故乡。 </p>
<p> 床前明月光,疑是地上霜。
举头望明月,低头思故乡。 </p>
<p> 床前明月光,疑是地上霜。
举头望明月,低头思故乡。 </p>
</body>
</html>
标题字
类似于word中的样式
<!doctype html>
<html>
<head>
<title>网页标题</title>
</head>
<body>
<h1>标题1</h1>
<h2>标题2</h2>
<h3>标题3</h3>
<h4>标题4</h4>
<h5>标题5</h5>
<!--换行通过br标签来实现,这种只有单个的标签称为独目标签-->
hello<br> world!
<!--hr实现横线,可以设置比例和颜色,语法太松散了,单引号双引号没有引号都无所谓-->
<hr color="red" width="50%">
</body>
</html>
预留格式
<pre>
床前明月光,疑是地上霜
举头望明月,低头思故乡
</pre>
<del>删除字</del>
<ins>插入字</ins>
<b>粗体字</b>
<i>斜体字</i>
10<sup>2</sup>
10<sub>m</sub>
<font color='red' size='50'>字体标签</font>
实体符号
显示大于小于
需要转义
实体符号以&开始,以分号结束
b< a>c
加空格
a bc
表格
一个表是一个table,table的一行是tr
tr的一格是td
<!doctype html>
<html>
<head>
<title>表格</title>
</head>
<body>
<!--设置表格的边框为1像素,宽度占比60%,高度为100px -->
<h1 align="center">员工信息表</h1>
<table align="center" border="1px" width="60%" height="500px">
<!--设置对齐方式align-->
<tr align="center">
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>
<tr>
<td>g</td>
<td>h</td>
<td align="right">i</td>
</tr>
</table>
</body>
</html>
合并单元格
row合并
留上弃下
column合并
留左弃右
<!doctype html>
<html>
<head>
<title>表格</title>
</head>
<body>
<!--设置表格的边框为1像素,宽度占比60%,高度为100px -->
<h1 align="center">员工信息表</h1>
<table align="center" border="1px" width="60%" height="500px">
<!--设置对齐方式align-->
<tr align="center">
<td colspan="2">ab</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td rowspan="2">cf</td>
</tr>
<tr>
<td>g</td>
<td>h</td>
</tr>
</table>
</body>
</html>
<!doctype html>
<html>
<head>
<title>表格,th标签</title>
</head>
<body>
<!--设置表格的边框为1像素,宽度占比60%,高度为100px -->
<h1 align="center">员工信息表</h1>
<table align="center" border="1px" width="60%" height="500px">
<!--设置对齐方式align-->
<tr>
<th>员工编号</th>
<th>员工薪资</th>
<th>部门名称</th>
</tr>
<tr>
<td>员工编号</td>
<td>员工薪资</td>
<td>部门名称</td>
</tr>
<tr align="center">
<td colspan="2">ab</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td rowspan="2">cf</td>
</tr>
<tr>
<td>g</td>
<td>h</td>
</tr>
</table>
</body>
</html>
th标签自动加粗和居中
thead tbody tfoot
将表格切分成三部分,只起到一个分区的作用
<!doctype html>
<html>
<head>
<title>表格,th标签</title>
</head>
<body>
<!--设置表格的边框为1像素,宽度占比60%,高度为100px -->
<h1 align="center">员工信息表</h1>
<table align="center" border="1px" width="60%" height="500px">
<!--设置对齐方式align-->
<thead>
<tr>
<th>员工编号</th>
<th>员工薪资</th>
<th>部门名称</th>
</tr>
</thead>
<tbody>
<tr>
<td>员工编号</td>
<td>员工薪资</td>
<td>部门名称</td>
</tr>
<tr align="center">
<td colspan="2">ab</td>
<td>c</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>d</td>
<td>e</td>
<td>c</td>
</tr>
<tr>
<td>g</td>
<td>h</td>
<td>f</td>
</tr>
</tfoot>
</table>
</body>
</html>
背景色、背景图片和图片
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>背景颜色</title>
</head>
<!--文件放在同一目录下-->
<body bgcolor="red" background="周杰伦.jpg">
</body>
</html>
图片
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>背景颜色</title>
</head>
<!--设置宽度,高度会随之缩放-->
<body>
<!--如果开始和结束标签中间不需要加任何东西,那么可以省略结束标签,在开始标签末尾加上斜杠-->
<img src="周杰伦.jpg" width="200px" title="悬停到图片上就显示我是周杰伦" alt="图片加载失败就显示这句话"/>
</body>
</html>
超链接
hot reference
href
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>超链接</title>
</head>
<body>
<a href="http://www.baidu.com">百度</a>
<!--通过设置target可以控制是在新界面打开还是在原有网页打开 _blank 和 _self-->
<a href="http://baidu.com" target="_blank">
<img src="周杰伦.jpg"/>
</a>
</body>
</html>
列表
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>列表</title>
</head>
<body>
<!--ol和ul用于控制某一个层级,li用于控制该层级的各个元素-->
<ol type="a">
<li>大鱼吃小鱼</li>
<ol>
<li>小鱼吃虾米</li>
</ol>
</ol>
<ul>
<li>中国</li>
<ul>
<li>北京</li>
<li>上海</li>
<ul type="circle">
<li>浦东区</li>
<li>虹桥区</li>
</ul>
</ul>
</ul>
</body>
</html>
表单
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>表单</title>
</head>
<body>
<!--form标签的action属性用来指定服务器地址url,向服务器发送request,且input必须放到form里面才行-->
<form action="http://www.baidu.com">
<!--表单比超链接更优异的一点就是可以传递数据-->
<!--写一个提交按钮,下面的第一个具备提交能力,第二个是普通按钮不能提交-->
<input type="submit" value="这里写的是按钮名"/>
<input type="button" value="这是简单的按钮">
</form>
</body>
</html>
简单写一个登录表
<!doctype html>
<html>
<head>
<title>表格</title>
</head>
<body>
<!--设置表格的边框为1像素,宽度占比60%,高度为100px -->
<h1 align="center">员工信息表</h1>
<!--提交格式 action?name=value&name=value&name=value...,解析后用Java的split分开读取 -->
<form action="">
<table align="center" border="1px">
<!--设置对齐方式align-->
<tbody>
<tr>
<td>用户名</td>
<!--有name才能提交-->
<!--表单项写了name的,一律会提交给服务器,不想提交,就不写name属性-->
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>密码</td>
<td><input type="text"/></td>
</tr>
<tr>
<td><input type="submit" value="登录"/></td>
<td><input type="reset" value="清空"></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
此时我们发现即使input设置了type为password,一旦传参后,还是看得到有password传过去,后面会处理这一问题
用户注册表单
首先我们看一个整体
给用户输入机会的,都不用写;让用户选的,需要给服务器传值的,都需要写value
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>表单</title>
</head>
<body>
<form method="post">
用户名
<input type="text" name="username"/>
<br>
密码
<input type="password" name="userpwd"/>
<br>
确认密码
<input type="password"/>
<br>
性别
<input type="radio" name="gender" value="1" checked/>
男
<input type="radio" name="gender" value="1"/>
女 <br>
兴趣爱好
<input type="checkbox" name="hobby" value="sing"/>
唱
<input type="checkbox" name="hobby" value="dance"/>
跳
<input type="checkbox" name="hobby" value="rap"/>
rap <br>
<!--给用户输入机会的,都不用写,需要给服务器传值的,都需要写value-->
学历
<select name="grade">
<option value="bachlor" selected>本科</option>
<option value="master">硕士</option>
<option value="doctor">博士</option>
</select>
<br>
简介
<!--文本域-->
<br>
<textarea name="introduce"></textarea>
<br>
<input type="submit" value="注册"/>
<input type="reset" value="清空"/>
</form>
</body>
</html>
再逐步分析
<form method="post">
使用post,传给服务器的参数不会在浏览器中直接看到
如果选get就能看到,默认是选的get
确认密码时不需要再写name,因为后面采用JS会解决这个问题
密码
<input type="password" name="userpwd"/>
<br>
确认密码
<input type="password"/>
如果name相同,那么这俩只能选一个,如果不同则可以多选,前提是radio表示的就是单选框
checked表示默认选中的
性别
<input type="radio" name="gender" value="1" checked/>
男
<input type="radio" name="gender" value="1"/>
女 <br>
CheckBox表示复选框,可以多选,name用法和单选一样,传的时候要写好value值
兴趣爱好
<input type="checkbox" name="hobby" value="sing"/>
唱
<input type="checkbox" name="hobby" value="dance"/>
跳
<input type="checkbox" name="hobby" value="rap"/>
rap <br>
下拉框用select,默认就不再是checked而是selected
学历
<select name="grade">
<option value="bachlor" selected>本科</option>
<option value="master">硕士</option>
<option value="doctor">博士</option>
</select>
<br>
写简介就需要文本域
<br>
<textarea name="introduce"></textarea>
<br>
最后写注册和清空
<input type="submit" value="注册"/>
<input type="reset" value="清空"/>
multiple可以支持多选,也可以通过size显示 显示条目数
<select multiple="multiple" size="3" name="grade" >
<option value="bachlor" selected>本科</option>
<option value="master">硕士</option>
<option value="doctor">博士</option>
file控件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>下拉列表支持多选</title>
</head>
<body>
<input type="file">
</select>
</body>
</html>
hidden控件
<input type="hidden" name="userid" value="111"/>
用户代码
<input type="text" name="usercode"/>
<input type="submit" value="提交"/>
提交时还是会传,但是网页上看不到
readonly和disabled
readonly和disabled值都不能修改,只能看,但readonly可以提交数据,disabled不能提交
<form action="" method="post">
<!--隐藏域,网页上看不到,但是表单提交的时候数据会自动提交给服务器-->
用户代码<input type="text" name="usercode" value="123" readonly />
<br>
用户密码<input type="text" name="userpwd" value="asd" disabled />
</form>
maxlength
限制文本框最长输入字符
请输入密码<input type="text" maxlength="3" />
id值
任何元素或者节点都有id值,在一个html中,id值不能重复,使获取节点更为方便
表单提交数据的时候,只和name有关,和id无关
总体来看,各个标签就是一颗document树下的各个节点
通过id来定为节点,便于后期进行增删改查
div和span
div和span都可以称为图层
有利于整个页面的布局
盒子套盒子,嵌套操作,便于细分后的操作
定下div的x y坐标即可
div独占一行(默认情况)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>元素的id属性</title>
</head>
<body>
<div id="div1">我是一个div1</div>
<div id="div2">我是一个div2</div>
<span id="span1">我是span1</span> <span id="span2">我是span2</span>
</body>
</html>
结束时间:2021-4-7