前端学习day03-js高级

<!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;    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-lyslyslys

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值