-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path求和.html
More file actions
34 lines (29 loc) · 1.01 KB
/
求和.html
File metadata and controls
34 lines (29 loc) · 1.01 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
window.onload = function () {
var oNum1 = document.getElementById('num1');
var oNum2 = document.getElementById('num2');
var oBtn = document.getElementById('btn');
oBtn.onclick = function () {//定义点击按钮事件的函数
if (isNaN(oNum1) || isNaN(oNum2)) {
alert('输入的不是一个数字')
} else {
//parseInt、parseFloat字符串转数字
alert(parseFloat(oNum1.value) + parseFloat(oNum2.value));
//alert(oNum1.value+oNum2.value);//12+5结果显示为125;
}
};
};
</script>
</head>
<body>
<input id="num1" type="text" />
<input id="num2" type="text" />
<input id="btn" type="button" value="sum" />
</body>
</html>