java script

作者:原创时间:2022-04-19
文档

java script是什么?让我们一起来了解一下吧!

java script是一种客户端脚本语言。它是作用在客户端浏览器里,并且不需要编译,可以很快的被浏览器自带的解析引擎运行。

java script有以下特点:

1. 语法与c、java相似,可以用任意文字编辑工具

2. 由浏览器的解析引擎运行

3. 以对象为基础

4. 是一种弱类型语言

java script有六种数据类型:string、boolean、null、number、undefined、object。

实战举例,具体步骤如下:

let big = document.querySelector('.big');
        let small = document.querySelector('.small');
        let NS = document.querySelector('.l');
        let WE = document.querySelector('.r');
        let box = document.querySelector('.box');
        let Box = document.querySelector('.Box');
 
 
        // 倒计时模块
        var longNum = 10;
        var shortNum = 3;
        big.addEventListener('click', function () {
            let inputNum = prompt('请输入你想设置的秒数:');
            longNum = inputNum == '' ? longNum : inputNum;
        })
        small.addEventListener('click', function () {
            let inputNum = prompt('请输入你想设置的秒数:');
            shortNum = inputNum == '' ? longNum : inputNum;
        })
        green();
        Green = setInterval(green, 1000);
 
        function green() {
            NS.children[2].className = 'green_s';
            point(Box);
            NS.children[2].innerHTML = longNum;
            WE.children[0].className = 'red_s';
            caveat(box);
            WE.children[0].innerHTML = longNum;
            if (longNum == -1) {
                clearInterval(Green);
                NS.children[2].className = 'green_end';
                del(Box);
                NS.children[2].innerHTML = '';
                WE.children[0].className = 'red_end';
                del(box);
                WE.children[0].innerHTML = '';
                longNum = 10;
                NS.children[1].className = 'yellow_s';
                WE.children[1].className = 'yellow_s';
                yellow();
                Yellow = setInterval(yellow, 1000);
                remind(box);
                remind(Box);
            }
            longNum--;
        }
 
        function yellow() {
            NS.children[1].innerHTML = shortNum;
            WE.children[1].innerHTML = shortNum;
            if (shortNum == -1) {
                del(box);
                del(Box);
                clearInterval(Yellow);
                NS.children[1].className = 'yellow_end';
                NS.children[1].innerHTML = '';
                WE.children[1].className = 'yellow_end';
                WE.children[1].innerHTML = '';
                shortNum = 3;
                NS.children[0].className = 'red_s';
                caveat(Box);
                WE.children[2].className = 'green_s';
                point(box);
                red();
                Red = setInterval(red, 1000);
            }
            shortNum--;
        }
 
        function red() {
            NS.children[0].innerHTML = longNum;
            WE.children[2].innerHTML = longNum;
            if (longNum == -1) {
                clearInterval(Red);
                NS.children[0].className = 'red_end';
                del(Box);
                NS.children[0].innerHTML = '';
                WE.children[2].className = 'green_end';
                del(box);
                WE.children[2].innerHTML = '';
                longNum = 10;
                NS.children[2].className = 'green_s';
                WE.children[2].className = 'green_end';
                green();
                Green = setInterval(green, 1000);
            }
            longNum--;
        }
 
        function caveat(concent) {
            concent.style.color = 'red';
            concent.innerHTML = '闯红灯,等着大家都去你家吃席';
        }
 
        function remind(concent) {
            concent.style.color = 'yellow';
            concent.innerHTML = '黄灯了,还没过去的抓紧时间,马上车就来撞你了';
        }
 
        function point(concent) {
            concent.style.color = 'green';
            concent.innerHTML = '绿灯也要注意安全哟!';
        }
 
        function del(concent) {
            concent.innerHTML = '';
        }

以上就是小编今天的分享了,希望可以帮助到大家。

显示全文
java selector java selenium java semaphore java separator java sequence java serializable java serializable接口 java serialversionuid java setlayout java platform java settimeout java plug-in java sftp java plugin java pojo java portal java sha256加密 java shuffle java simhash java simpledateformat java sandbox java rxjava java runtime.exec java runnable java rtp java rsa私钥加密 java rsa公钥加密 java pipeline java ping java phoenix java paypal java path java rsa加密 java rotate java reverse java reverse() java retrofit java resume java resultset java result