-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfgm32.html
69 lines (66 loc) · 1.82 KB
/
fgm32.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
<!Doctype html>
<head>
<meta charset='utf-8'>
<title>用parseInt解析数字,并求和</title>
<style>
body{font:12px/1.5 arial;text-align:center;}
.f-text{width:50px;border:1px solid #ccc;background:#f0f0f0;font-family:inherit;padding:3px;}
span{color:green;padding-right:10px;font-weight:700;}
strong{padding:0 10px;}
</style>
<script type="text/javascript">
window.onload = function ()
{
// var aInput = document.getElementsByTagName("input");
// var aSpan = document.getElementsByTagName("span")[0];
// var i = 0;
// for (i = 0; i < aInput.length - 1; i++)
// {
// aInput[i].onkeyup = function ()
// {
// this.value = this.value.replace(/[^\d]/,"")
// }
// }
// aInput[2].onclick = function ()
// {
// (aInput[0].value == "" || aInput[1].value == "") ?
// alert("请输入数字!") :
// aSpan.innerHTML = parseInt(aInput[0].value) + parseInt(aInput[1].value);
// }
// 案例
var ainput= document.querySelectorAll('.f_text'),
binput= document.querySelector('.all');
cspan = document.querySelectorAll('span')[0];
binput.onclick=function(){
if (ainput[0].value==''||ainput[1].value=='') {
alert("请输入数字!")
}
cspan.innerHTML=parseInt(ainput[0].value)+parseInt(ainput[1].value);
}
};
</script>
</head>
<body>
<input type="text" class="f_text" value="" />
<strong>+</strong>
<input type="text" class="f_text" value="" />
<strong>=</strong>
<span>?</span>
<input type="button" value="求和" class="all" />
<script>
window.onload = function() {
console.log('html load')
}
</script>
<script>
setTimeout(function () {
var img = document.createElement('img')
img.src = 'http://krspace.cn/images/header.9eac16910557e285bee0ad69b94ca1df.png'
img.onload = function () {
console.log('img load')
}
document.body.appendChild(img)
}, 0)
</script>
</body>
</html>