⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙

代码-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>
posted @ 2018-10-18 01:50  羊驼可以吃吗  阅读(210)  评论(0编辑  收藏  举报
⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙ ⊙︿⊙