<!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>
转载于:https://www.cnblogs.com/phpisfirst/p/9819143.html