-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
52 lines (42 loc) · 1.46 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IFE JavaScript Task 01</title>
</head>
<body>
<label>请输入北京今天空气质量:<input id="aqi-input" type="text"></label>
<button id="button">确认填写</button>
<div>您输入的值是:<span id="aqi-display">尚无录入</span></div>
<script type="text/javascript">
(function () {
/*
在注释下方写下代码
给按钮button绑定一个点击事件
在事件处理函数中
获取aqi-input输入的值,并显示在aqi-display中
*/
var input = document.getElementById('aqi-input');
var display = document.getElementById('aqi-display');
var button = document.getElementById('button');
function addEvent(target, type, func) {
if (target.addEventListener)
/*监听IE9,谷歌和火狐,使用冒泡机制*/
target.addEventListener(type, func, false);
else if (target.attachEvent)
/*IE8*/
target.attachEvent(type, func);
else
target['on' + type] = func;
}
function show() {
var value = input.value;
/*检测左右两端空格*/
if (value.replace(/(^\s*)|(\s*$)/g, ""))
display.textContent ? display.textContent = value : display.innerText = value;
}
return addEvent(button, 'click', show)
})();
</script>
</body>
</html>