-
Notifications
You must be signed in to change notification settings - Fork 0
/
0821-10-tag-js.html
34 lines (30 loc) · 1.05 KB
/
0821-10-tag-js.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<!-- event,事件物件,包成一個看不見的function,event是從那個物件傳過來的 -->
<!-- 點的時候會先觸發事件,再連過去,可以加個提示窗 -->
<body>
<a href="https://tw.yahoo.com" onclick="func(event)">aaa</a>
<br>
<!-- 假連結 -->
<a href="javascript: func2(12)">bbb</a>
<script>
//是從onclick="func(event)"設定過來的,func()內參數可以隨便命名
//但是onclick="func(event)"內的event不行隨便改
function func(e) {
if (!confirm('真的要連過去嗎?')) {
e.preventDefault(); //取消原本功能
}
}
function func2(e) {
console.log(e);
}
</script>
</body>
</html>