事件委托
<!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>attr-prop</title>
<style>
#box {
width: 400px;
background: green ;
}
.a {
width: 200px;
height: 200px;
background: red;
}
.b {
width: 100px;
height: 100px;
background: yellow;
}
</style>
</head>
<body>
<div id="box">
<div class="a">a的事件委托</div>
<br>
<br>
<br>
<div class="b">b的事件委托</div>
<br>
<br>
<br>
</div>
<script src="../zepto.js"></script>
<script src="../touch.js"></script>
<script>
$(function(){
$('#box').on('touchstart','.a',function(){
alert('a 触发的事件')
console.log(this);
})
$('#box').on('touchstart','.b',function(){
console.log(this)
alert('b 触发的事件')
})
$('#box').append('<p class="a">我是新添加的</p>')
})
</script>
</body>
</html>
我是Eric,手机号是13522679763

浙公网安备 33010602011771号