-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScriptDemo.html
More file actions
56 lines (51 loc) · 1.36 KB
/
JavaScriptDemo.html
File metadata and controls
56 lines (51 loc) · 1.36 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript示例程序</title>
</head>
<body>
<!-- 功能1 做出反应 -->
<p>
<button id="first" type="button" onclick="alert('Hello! I love you!')">做出反应</button>
</p>
<hr/>
<!-- 功能2 改变内容 -->
<button id="second" type="button" onclick="changeContent();">改变HTML内容</button>
<p id="change">我要开始变了!</p>
<hr/>
<script>
function changeContent() {
x = document.getElementById("change");
x.innerHTML = "我已经变化了!";
}
</script>
<!-- 功能3 改变样式,大小-->
<button id="third" type="button" onclick="changeStyle();">改变HTML样式</button>
<p id="change2">样式变化</p>
<hr/>
<script>
function changeStyle() {
x = document.getElementById("change2");
x.style = "font-size:30px; color:red";
}
</script>
<!-- 功能4 验证输入 -->
<div>输入一个大于5的数字:</div>
<input id="va" type="text" value="10">
<button id="fourth" type="button" onclick="validate_test();">验证输入</button>
<hr/>
<script>
function validate_test() {
var x = document.getElementById("va").value;
if (x > 5) {
alert("大于5!")
} else if (x < 5) {
alert("小于5!")
} else {
alert("等于5!")
}
}
</script>
</body>
</html>