zoukankan      html  css  js  c++  java
  • javaScript——案例演示:点击有惊喜

    一、方式一

    几个页面点击一次切换一次

    步骤:

    1.建box1,设置box1的宽 高 背景色 位置 其内部文本行高 字体大小 字体颜色
    
    2.设置box1点击事件

    代码演示:

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            .box{
                 200px;
                height: 200px;
                background-color: red;
                margin: auto;
                text-align: center;
                line-height: 200px;
                font-size: 30px;
                color: white;
            }
    
    
        </style>
    </head>
    <body>
    <div class="box">
        点击有惊喜!
    </div>
    <script>
        var box=document.getElementsByClassName("box")[0]
        var count=0
        box.onclick=function () {
            count++
            if (count  == 1){
                this.style.backgroundColor="green"
                this.innerText="继续点击!"
            }else if(count  == 2){
                this.style.backgroundColor="yellow"
                this.innerText="精彩即将揭晓"
    
            }else if(count  == 3){
                this.style.backgroundColor="pink"
                this.innerText="骗你的傻逼"
    
            }else {
                this.style.backgroundColor="red"
                this.innerText="点击有惊喜!"
                count=0
    
            }
    
        }
    
    </script>
    </body>
    </html>

    二、方式二

    步骤一样,就是在方式一上稍有改动

    利用javaScript取余用法

    改动代码演示:

    box.onclick=function () {
            count++
            if (count % 4 == 1){
                this.style.backgroundColor="green"
                this.innerText="继续点击!"
            }else if(count % 4 == 2){
                this.style.backgroundColor="yellow"
                this.innerText="精彩即将揭晓"
    
            }else if(count % 4 == 3){
                this.style.backgroundColor="pink"
                this.innerText="骗你的傻逼"
    
            }else {
                this.style.backgroundColor="red"
                this.innerText="点击有惊喜!"
                // count=0
            }
  • 相关阅读:
    Java8基础学习之Object类
    Java8基础之equals方法和==的区别
    Spring集成ElasticSearch
    ElasticSearch常用的查询过滤语句
    数据库查看SQL执行计划
    数据库优化总结
    ElasticSearch之集群原理
    curl命令操作ElasticSearch总结
    ElasticSearch相关概念总结
    ElasticSearch基础入门
  • 原文地址:https://www.cnblogs.com/guojieying/p/13718221.html
Copyright © 2011-2022 走看看