-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.html
29 lines (29 loc) · 977 Bytes
/
12.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>触发器</title>
<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
$(function(){
$('a').click(function(){
alert('a');
});
// $('a')[0].onclick = function(){
// alert('a');
// };
//$('a')[0] 转化为dom对象了
//$('a').trigger('click');//此时并没有触发默认行为进行跳转 可以利用冒泡
console.log($('a')[0]);
$('span').click(function(){
alert('span');});
//$('a')[0].click();//原生js函数click也代表触发点击
//$('span').trigger('click');
$('span').triggerHandler('click');//triggerHandler不会触发默认行为 也不会触发冒泡
});
</script>
</head>
<body>
<a href="http://www.baidu.com" target="_blank"><span>baidu</span></a>
</body>
</html>