javascript设置了阻止冒泡后,又怎么再次允许事件冒泡 20
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Document</title></head...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="aaa" style="width:150px; height:150px; background:red;">
<div class="bbb" style="width:100px; height:100px;background:green">sdfsdfsdf</div>
</div>
</body>
<script src="jquery.js"></script>
<script>
$('.aaa').on('click', function(event) {
event.preventDefault();
alert('aaa');
});
$('.bbb').on('click', function(event) {
event.stopPropagation();
alert('bbb');
});
$('.bbb').on('click', function(event) {
//由于某原因,上面的代码不可以改,但是之前的bbb已经设置了阻止冒泡,在这里面,怎么才能允许冒泡呢?
});
</script>
</html> 展开
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="aaa" style="width:150px; height:150px; background:red;">
<div class="bbb" style="width:100px; height:100px;background:green">sdfsdfsdf</div>
</div>
</body>
<script src="jquery.js"></script>
<script>
$('.aaa').on('click', function(event) {
event.preventDefault();
alert('aaa');
});
$('.bbb').on('click', function(event) {
event.stopPropagation();
alert('bbb');
});
$('.bbb').on('click', function(event) {
//由于某原因,上面的代码不可以改,但是之前的bbb已经设置了阻止冒泡,在这里面,怎么才能允许冒泡呢?
});
</script>
</html> 展开
展开全部
$('.aaa').on('click', function(event) {
event.preventDefault();
alert('aaa');
});
$('.bbb').on('click', function(event) {
event.stopPropagation();
alert('bbb');
});
$('.bbb').off('click').on('click',function(){
alert('bbb2');
})
只能做到这样,在第一次绑定之后,解绑,并且重新绑定对应的方法(方法中去掉stopPropagation)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询