触发相同命名空间的事件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQery-自定义事件面试题</title>
<style>
* {
margin: 0;
padding: 0;
}
.father {
width: 200px;
height: 200px;
background: red;
}
.son {
width: 100px;
height: 100px;
background: blue;
}
</style>
<script src="../jquery-3.3.1.js"></script>
<script>
$(function(){
$(".father").on("click.ls",function(){
alert("father click1");
});
$(".father").on("click",function(){
alert("father click2");
});
$(".son").on("click.ls",function(){
alert("son click1");
});
$(".son").trigger("click");
//空间名相同冒泡触发
})
</script>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
<a href="https://www.bilibili.com/"><span>bilibili干杯!</span> </a>
<form action="http://www.taobao.com">
<input type="text">
<input type="submit">
</form>
</body>
</html>