zoukankan      html  css  js  c++  java
  • 代码-JS之点击换色判断

    <!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>
        <!--编写css-->
        <style>
            .a{
                color:red;
            }
            .b{
                color:blue;
            }
        </style>
    </head>
    <body>
    <!--编写HTML-->
    <p>hello world</p>
    <!--编写JavaScript-->
    <script>
        //找到节点并绑定点击事件
        document.querySelector('p').onclick = function () {
            //进行判断
            if(this.className != 'a'){
                this.className = 'a';
            }else{
                this.className = 'b';
            }
        };
    </script>
    
    </body>
    </html>
    
    Copyright [2018] by [羊驼可以吃吗] form [https://www.cnblogs.com/phpisfirst/]
  • 相关阅读:
    leetcode211
    leetcode209
    leetcode201
    leetcode1396
    leetcode1395
    leetcode1394
    leetcode1386
    leetcode1387
    leetcode1382
    leetcode1376
  • 原文地址:https://www.cnblogs.com/phpisfirst/p/9819143.html
Copyright © 2011-2022 走看看