0616作业
一、 前端表格实现购物车(表格实现)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>表格实战: 购物车</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<!-- 表格 -->
<table>
<!-- 标题 -->
<caption>
我的订单
</caption>
<!-- 头部 -->
<thead>
<tr>
<th>ID</th>
<th>商品</th>
<th>单价/元</th>
<th>单位</th>
<th>数量</th>
<th>金额/元</th>
</tr>
</thead>
<!-- 主体 -->
<tbody>
<tr>
<td>SN-101011</td>
<td>2080ti显卡</td>
<td>8999</td>
<td>块</td>
<td>1</td>
<td>8999</td>
</tr>
<tr>
<td>SN-102012</td>
<td>144hz显示器</td>
<td>5000</td>
<td>台</td>
<td>2</td>
<td>10000</td>
</tr>
<tr>
<td>SN-103013</td>
<td>漫步者音箱</td>
<td>399</td>
<td>只</td>
<td>5</td>
<td>1995</td>
</tr>
<tr>
<td>SN-104014</td>
<td>SSD移动硬盘</td>
<td>888</td>
<td>个</td>
<td>2</td>
<td>1776</td>
</tr>
<tr>
<td>SN-105015</td>
<td>华硕玩家国度路由器</td>
<td>1000</td>
<td>台</td>
<td>3</td>
<td>3000</td>
</tr>
</tbody>
<!-- 底部 -->
<tfoot>
<tr>
<td colspan="4">总计:</td>
<!-- 合并单元格,这里合并4格,后面要响应减掉4个<td> ,否则格式会乱-->
<td>13</td>
<td>25770</td>
</tr>
</tfoot>
</table>
<!-- 结算按钮 -->
<div>
<button>结算</button>
</div>
</body>
</html>
css代码,通过link引入
html {
font-size: 14px;
}
table {
/* 将单元格之间的间隙去掉 */
border-collapse: collapse;
width: 70%;
margin: auto;
color: #666;
font-weight: lighter;
text-align: center;
}
/* 表格线直接添加到单元格上面,线条是围绕单元格的 */
table thead th,
table td {
border-bottom: 1px solid #ccc;
padding: 10px;
}
/* 标题样式 */
table caption {
font-size: 1.5rem;
margin-bottom: 15px;
color: green;
}
table th {
font-weight: lighter;
color: green;
}
table thead tr:first-of-type {
background-color: lightcyan;
}
/* 隔行变色 */
table tbody tr:nth-of-type(even) {
background-color: lightgreen;
}
/* 鼠标悬停效果 */
table tbody tr:hover {
background-color: lightblue;
}
/* 底部样式 */
table tfoot td {
border-bottom: none;
color: coral;
font-size: 1.2rem;
font-weight: bolder;
}
/* 结算按钮 */
/*因为只有一个按钮,实际效果last-of-type和first-of-type其实都是一样的*/
body div:last-of-type {
width: 70%;
margin: 10px auto;
}
body div:first-of-type button {
/* 靠右 */
float: right;
width: 120px;
height: 32px;
background-color: seagreen;
color: white;
border: none;
/* 设置鼠标样式,变成手指的形状 */
cursor: pointer;
}
body div:first-of-type button:hover {
background-color: coral;
font-size: 1.2rem;
/* 改表字体相对大小 */
}
二、表单实现用户注册界面(表单实现)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>表单用户注册界面案例</title>
</head>
<body>
<h3>用户注册</h3>
<!-- form+input.... -->
<form action="" method="POST">
<!-- 控件组 -->
<fieldset>
<legend>基本信息(必填)</legend>
<div>
<label for="my-username">账号:</label>
<input
type="text"
id="my-username"
name="username"
placeholder="6-15位字符"
autofocus
/>
</div>
<div>
<label for="email-id">邮箱:</label>
<input
type="email"
<!限制只能获取email格式>
name="email"
id="email-id"
placeholder="demo@example.com"
/>
</div>
<!-- 密码 -->
<div>
<label for="pwd-2">密码:</label>
<input type="password"" name="password1" id="pwd-2"
placeholder="不少于6位且字母+数字" />
</div>
<div>
<label for="pwd-1">确认:</label>
<input type="password" name="password2" id="pwd-1" />
</div>
</fieldset>
<fieldset>
<legend>扩展信息(选填)</legend>
<div>
<label
>生日:
<input type="date" name="birthday" />
</label>
</div>
<div>
<!-- 单选按钮 -->
<label for="secret">性别:</label>
<!-- 单选按钮中的name属性名必须相同 -->
<input type="radio" name="gender" value="male" id="male" /><label
for="male">男</label
>
<input type="radio" name="gender" value="female" id="female" /><label
for="female">女</label>
<input type="radio" name="gender" value="secret" id="secret" checked/><label for="secret">保密</label>
</div>
<div>
<!-- 复选框 -->
<label for="programme">爱好</label>
<!-- 因为复选框返回是一个或多个值,最方便后端用数组来处理, 所以将name名称设置为数组形式便于后端脚本处理 -->
<input type="checkbox" name="hobby[]" id="game" value="game" /><label
for="game"
>打游戏</label
>
<input
type="checkbox"
name="hobby[]"
value="shoot"
id="shoot"
/><label for="shoot">摄影</label>
<input
type="checkbox"
name="hobby[]"
value="programme"
id="programme"
checked
/><label for="programme">编程</label>
</div>
<div>
<!-- 选项列表 -->
<label for="brand">地址:</label>
<input type="search" list="phone" name="brand" id="brand" />
<datalist id="phone">
<option value="广东" label="广东"> </option>
<option value="浙江" label="浙江"></option>
<option value="四川" label="四川"> </option>
</datalist>
</div>
</fieldset>
<fieldset>
<legend>其它信息(选填)</legend>
<!--文件上传-->
<div>
<label for="uploads">上传头像:</label>
<input
type="file"
name="user_pic"
id="uploads"
accept="image/png, image/jpeg, image/gif"
/>
</div>
<!--文本域-->
<div>
<label for="resume">简历:</label>
<!--注意文本域没有value属性-->
<textarea
name="resume"
id="resume"
cols="30"
rows="5"
placeholder="不超过500字"
>
序号 | 表单属性 | 特征 |
---|---|---|
1 | type=”text” | 明文 |
2 | type=”email” | 限制只能输入邮箱格式 |
3 | type=”date” | 日期格式 |
4 | type=”radio” | 单选,单选按钮中的name属性名必须相同 |
5 | type=”checkbox” | 复选框,建议name名称设置为数组形式便于后端服务器处理 |
6 | type=”search” | 下来列表,如省市联动 |
7 | type=”file” | 文件传输 |
8 | type=”hidden” | 隐藏域, 无需用户输入但是系统需要的信息,如Id,登录的时间 |
<label for=""> for中的名称必须和id的名称一样,才能实现绑定点击文字跳转到输入框
单选、复选等表单属性中设置checked 表示默认选中的项
name属性很重要,是传递给后台服务器的变量值