Blogger Information
Blog 34
fans 0
comment 0
visits 39110
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js基础Math与Date对象——第五期线上——2019-3-28
黄健的博客
Original
620 people have browsed it

今日课程:

1.JavaScript隔行换色

2.JavaScript全选

3.Math对象(随机色)

4.日期对象(倒计时)


作业:

    全选:

                function checkAll(){
            var objList=document.getElementsByName('list');
            for (var i =0;i<objList.length;i++) {
                 objList[i].checked=true;
            }
        }
       
        function checkOut(){
            var objList=document.getElementsByTagName('input');
            for(var i=0;i<objList.length;i++){
                if(objList[i].checked){
                    objList[i].checked=false;
                }else{
                    objList[i].checked=true;
                }

    点击全选时,获取所有的多选框,循环改变每个的checked属性;点击全不选的时候也是循环所有的多选框然后判断,如果选中的多选框的checked属性为false

    随机色:

    

function bg_Color(){
var bg="#"//背景色
var r=Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10);
var g=Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10);
var b=Math.floor(Math.random()*10).toString()+Math.floor(Math.random()*10);
bg+=r+g+b
// console.log(bg)
document.getElementsByTagName('body')[0].style.background=bg
         }

 背景色颜色可由 6个数字字符串组成,例 #123145;

定义三个变量,每个变量由两个数字的字符串组成,最后拼接成一个颜色字符串


倒计时:

    

var i = 4;
function fn(){
    if(i>0){
            Espan.innerHTML=i;
            i--;
        }else{
window.location.href="http://www.php.cn/"//跳转新页面
       }
        }
        
        setInterval("fn()",1000)

使用定时器,每秒调用变量减1的函数,里面判断 被减的变量 小于 0 的时候就跳转页面

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post