Javascript 隐藏目标div后点击事件冒泡
我使用Photosweep插件。当我点击关闭按钮时,Photosweep关闭。但在Photosweep隐藏后,在Photosweep div下的图像上触发了div tap事件。我如何防止这种行为? 例如:Javascript 隐藏目标div后点击事件冒泡,javascript,jquery,jquery-mobile,tap,Javascript,Jquery,Jquery Mobile,Tap,我使用Photosweep插件。当我点击关闭按钮时,Photosweep关闭。但在Photosweep隐藏后,在Photosweep div下的图像上触发了div tap事件。我如何防止这种行为? 例如: div { 宽度:300px; 高度:300px; } .首先 { 背景色:黑色; } 第二 { 宽度:200px; 高度:200px; 位置:绝对位置; 顶部:50px; 左:50px; 背景色:红色; z指数:2; } $(函数() { $('.first')。点击(函数() { $(t
div
{
宽度:300px;
高度:300px;
}
.首先
{
背景色:黑色;
}
第二
{
宽度:200px;
高度:200px;
位置:绝对位置;
顶部:50px;
左:50px;
背景色:红色;
z指数:2;
}
$(函数()
{
$('.first')。点击(函数()
{
$(this.css({backgroundColor:'green'});
});
$('.second').tap(函数()
{
$(this.hide();
});
})
工作原理
-轻触第二个div-第二个div上触发的抽头事件
-第二分区隐藏
-第一个div上触发的tap事件 我想要什么
-轻触第二个div
-第二个div上触发的抽头事件
-第二分区隐藏
-什么也没发生 在第二个div tap处理程序中,我应该如何防止在第一个div上触发tap事件 我更改了示例以查看触发了哪些事件
$(function()
{
$('.first').bind('vmousedown',function()
{
info('vmousedown first' )
}).bind('vmouseup', function(){
info('vmouseup first')
})
.bind('click',function(){
info('click first');
}).bind('tap', function(){
info('tap first');
});
$('.second').bind('vmousedown',function()
{
info('vmousedown second' )
}).bind('vmouseup', function(){
info('vmouseup second');
})
.bind('click',function(){
info('click second');
}).bind('tap', function(){
info('tap second');
$(this).hide();
});
});
电脑输出:vmousedown秒数
vmouseup秒数
单击第二个
点击第二 安卓: vmousedown秒数
vmouseup秒数
点击第二个
vmousedown优先
vmouseup优先
首先单击
首先点击我认为问题在于您使用的是jQM Alpha(jquery.mobile-1.0a4.1.js),升级到最新版本,我认为它可以正常工作。您还可以绑定点击事件
.bind('tap',function()
我认为问题在于您正在使用jQM Alpha(jquery.mobile-1.0a4.1.js),升级到最新版本,我认为它可以正常工作。此外,您还可以绑定tap事件
.bind('tap',function()
$(function()
{
$('.first').tap(function()
{
$(this).css({backgroundColor : 'green'});
});
$('.second').tap(function()
{
$(this).hide();
});
});
<!DOCTYPE HTML >
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
</head>
<body>
<div class='first'></div>
<div class='second'></div>
</body>
</html>
div
{
width: 300px;
height: 300px;
}
.first
{
background-color: black;
}
.second
{
width: 200px;
height: 200px;
position: absolute;
top : 50px;
left: 50px;
background-color: red;
z-index: 2;
}