-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo21.html
42 lines (42 loc) · 1.1 KB
/
demo21.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body{
text-align: center;
}
.box-active{
background-color: black;
color: white;
}
</style>
</head>
<body>
<div class="box">
<h1>hello</h1>
<p>jirengu</p>
</div>
<button type="submit" id="add">增加</button>
<button id="remove">移除</button>
<button id="toggle">切换</button>
</body>
<script>
var box = document.getElementsByClassName("box")[0];
var add = document.getElementById("add");
var remove = document.getElementById("remove");
var toggle = document.getElementById("toggle");
(toggle.onclick = function(){
box.classList.toggle("box-active");
})();
(add.onclick = function(){
box.classList.add("box-active");
})();
(remove.onclick = function(){
box.classList.remove("box-active");
})();
</script>
</html>