-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom.html
126 lines (97 loc) · 3.89 KB
/
dom.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<style>
#container{
width: 400px;
height: 400px;
position: relative;
background: yellow;
}
#animate{
width: 50px;
height: 50px;
position: absolute;
background: red;
}
</style>
<body>
<div id="demo">
<p class="p1">Heading 1.</p>
<h1 id="demo2"></h1>
</div>
<p id="demo3"></p>
<p><button onclick="myMove()">单击我</button></p>
<div id="container">
<div id="animate"></div>
</div>
<h1 onclick="this.innerHTML='🦀️🦀️!'">请点击此文本!</h1>
<h1 onclick="changeText(this)">请点击此文本!</h1>
<div><button id="myBtn">单击我</button></div>
<div>
<input type="text" id="fname" onchange="myFunction()">
</div>
<div onmouseover="mOver(this)" onmouseout="mOut(this)" style="background-color: azure; width:120px; height:20px;padding:40px;">请把鼠标移上来</div>
<div onmousedown="mDown(this)" onmouseup="mUp(this)" style="background-color: yellowgreen; width:120px; height:20px;padding:40px;">点击🖱️</div>
<div><button id="myBtn1">单击我myBtn1</button></div>
<div><button id="myBtn2">单击我myBtn2</button></div>
<div><button onclick="removeHandler()" id="myBtn3 ">删除</button></div>
<p id="demo4"></p>
<script>
var x=document.getElementById("demo");
var y=x.getElementsByTagName("p");
document.getElementById("demo2").innerHTML=y[0].innerHTML;
var z=document.querySelectorAll("p.p1");
document.getElementById("demo3").innerHTML=z[0].innerHTML;
document.write(Date());
function myMove(){
var elem = document.getElementById("animate");
var pos = 0;
var id = setInterval(frame,5);
function frame(){
if(pos==350) clearInterval(id);
else {
pos++;
elem.style.top=pos+"px";
elem.style.left=pos+"px";
}
}
}
function changeText(id){
id.innerHTML="Hello:)";
}
document.getElementById("myBtn").onclick=myMove;
function myFunction(){
var x=document.getElementById("fname");
x.value=x.value.toUpperCase();
}
function mOver(obj){
obj.innerHTML="🦀️🦀️🍋";
}
function mOut(obj){
obj.innerHTML="请8🐭⌚️1⃣️⬆️来";
}
function mDown(obj){
obj.style.backgroundColor="beige";
obj.innerHTML="松开鼠标";
}
function mUp(obj){
obj.style.backgroundColor="yellowgreen";
obj.innerHTML="谢谢您";
}
document.getElementById("myBtn1").addEventListener("click",myAlert);
function myAlert(){
alert("Hello World!")
}
//why????????????????????????????
//document.getElementById("myBtn2").addEventListener("click",myFunc(5,7));
document.getElementById("myBtn2").addEventListener("click",function(){myFunc(5,7);});
function myFunc(a,b){
var result = a*b;
document.getElementById("demo4").innerHTML = result;
}
function removeHandler(){
document.getElementById("myBtn1").removeEventListener("click",myAlert);
}
</script>
</body>
</html>