![](https://i-blog.csdnimg.cn/blog_migrate/fa7e1194925463dbaafb5062840e3cd3.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../css/day03.css"/>
<title>Document</title>
</head>
<body>
<div class="flex1">
<div class="flex1-1">
<div>
1、练习一:验证密码
①密码长度必须是6位的任意字符
②当鼠标离开文本输入框的时候就会触发的事件,所以我们需要在密码的input标签中添加一个离焦事件onblur,用来验证密码是否合法。
</div>
<div>
输入密码:<input type="text" id="password" onblur="myFunction1()">
</div>
</div>
<div class="flex1-2">
<div>
练习二:表格隔行换色,能够使用js实现表格隔行换色功能。
</div>
<div id="changecolor" class="flex1-2-1" onclick="changecolors()">点击换色</div>
<div>
<table>
<thead >
<tr class="selected1">
<td>
序号
</td>
<td>
名称
</td>
<td>
状态
</td>
</tr>
</thead>
<tbody>
<tr class="selected2">
<td>
序号
</td>
<td>
名称
</td>
<td>
状态
</td>
</tr>
<tr class="selected1">
<td>
序号
</td>
<td>
名称
</td>
<td>
状态
</td>
</tr>
<tr class="selected2">
<td>
序号
</td>
<td>
名称
</td>
<td>
状态
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="flex1-3">
<div>
练习三:日期
①使用Date对象,在页面回显当前年月日时分秒星期
</div>
<div id="showdata">
</div>
</div>
</div>
</body>
<script>
var today= new Date();
var year = today.getFullYear();
var month = today.getMonth() + 1;
var day = today.getDate();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
var xingqi = today.getDay();
document.getElementById('showdata').innerHTML="今天是"+year+"年"+month+"月"+day+"日"+" "+h+":"+m+":"+s+" "+"星期"+xingqi;
function myFunction1(){
var x=document.getElementById("password");
if(x.length != 6) {
alert("请输入六位密码")
}
}
var color2 = 'red';
var color1 = 'blue';
function changecolors(){
console.log( document.getElementsByClassName("selected1"))
color3 = color1
color1 = color2
color2 = color3
document.getElementsByClassName("selected1")[1].style.backgroundColor = color1;
document.getElementsByClassName("selected1")[0].style.backgroundColor = color1;
document.getElementsByClassName("selected2")[1].style.backgroundColor = color2;
document.getElementsByClassName("selected2")[0].style.backgroundColor = color2;
}
</script>
</html>
.flex1{
display: flex;
flex-direction: column;
}
.flex1-1{
display: flex;
flex-direction: column;
background-color: hotpink;
height: 100px;
width: 100%;
}
.flex1-2{
display: flex;
flex-direction: column;
background-color: white;
width: 100%;
}
.flex1-3{
display: flex;
flex-direction: column;
background-color: hotpink;
height: 200px;
width: 100%;
}
.flex1-2-1{
display: flex;
flex-direction: column;
width: 100%;
text-align: center;
background-color: lightblue;
}
table{
height: 200px;
width: 100%;
border-collapse: collapse;
text-align: center;
}
table,table tr td {
border:1px solid #ccc;
height: 70px;
}
table tr td{
padding: 5px 10px;
}
.selected1 {
background-color: red;
}
.selected2 {
background-color: blue;
}