-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
101 lines (78 loc) · 2.33 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<a href="http://www.baidu.com" onClick="doSomething(this)">百度</a>
<a href="somewhere.html"
onMouseOver="window.status = 'This link goes somewhere'; return true">somewhere</a>
<a href="somewhere.html" onClick="doSomething2(this)">doSomething2</a>
<a href="somewhere.html" onClick="return doSomething3(this)">doSomething3</a>
<a href="somewhereElse.html" onClick="return doSomething3(this)">doSomething3</a>
<a href="somewhereElse.html" id="doSomething4">doSomething4</a>
<p id="clickme">doSomething4</p>
</body>
<script>
function doSomething(obj) {
console.log(obj)
return confirm('Do you really want to follow ' + obj.innerHTML + 'link?')
}
function doSomething2(obj) {
console.log(obj.innerHTML)
event.preventDefault()
// obj now refers to the link
}
function doSomething3(obj) {
var linkTo = obj.href;
return confirm('Do you really want to follow the link to ' + linkTo + '?')
}
function aaa() {
console.log(this)
}
document.getElementById('doSomething4').onclick = function () {
event.preventDefault()
console.log(this)
aaa()
bbb()
}
function bbb() {
console.log(this)
}
var clickme = document.getElementById('clickme');
clickme.addEventListener('click', foo1, true);
clickme.onclick = foo2;
clickme.addEventListener('click', foo3, true);
function foo1(event) {
console.log(111);
}
function foo2(event) {
console.log(222);
}
function foo3(event) {
console.log(333);
}
function myFunction(arg1, arg2) {
this.firstName = arg1;
this.lastName = arg2;
console.log(this)
}
var x = new myFunction("John","Doe"); // This creates a new object
new function(){ console.log('立即执行') };
var elems = document.getElementsByTagName( 'a' )
for ( var i = 0; i < elems.length; i++ ) {
elems[i].addEventListener('click', (function(lockedInIndex){
return function(e){
e.preventDefault();
alert('I am link #' + lockedInIndex);
};
})(i),false);
}
function run(f){
return f();
}
run(function(){
console.log('....')
});
</script>
</html>