day 67 jobs

  • Red, yellow, and blue buttons, and a rectangular box of a 200X200px, clicking different buttons, box color will be switched to a specified color
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<style>
    .box {
        width: 200px;
        height: 200px;
        background-color: red;
    }
</style>

<body>
    <div id="d1">
        <p>
            <button @click="ck('red')">红</button>
            <button @click="ck('yellow')">黄</button>
            <button @click="ck('blue')">蓝</button>
        </p>

        <div class="box" :style="{backgroundColor: color}"></div>
    </div>
</body>
<script src="js/vue.js"></script>
</html>
<script>
    new Vue({
        el: '#d1',
        data: {
            color: 'red'
        },
        methods: {
            ck(color) {
                this.color = color;
            }
        }
    })
</script>
  • 200X200px of a rectangular box, click on the box itself, record clicks, 1 box turns pink, 2 to green, to blue three times, four times to return to pink, and so on
<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>Title</title>

</head>
<style>
    .wrap {
        width:200px;
        height:200px;
        background-color:red;
    }
</style>
<body>
<div id="d1">

   <div class="wrap" :style="{backgroundColor:color}" @click="changeColor"></div>

</div><script src="js/vue.js"></script>

<script>
   new Vue ({
       e1: '#d1',
       data: {
           color: 'black',
           count:0,
           colorTrans: ['pink','cyan','green']
       },
       method: {
           changeColor(){
               let i = this.count+1;
               this.color = this.colorTrans;
           }
       }
   })
</script>


</body>
</html>

Guess you like

Origin www.cnblogs.com/colacheng0930/p/12052462.html