没有jquery点击功能
not jquery click function
我要设置显示:none;在 id 上,但前提是您单击 id 本身而不是该 id 中的 img
$(":not('#lightbox img'),#lightbox").click(function() {
$("#lightbox").css( "display", "none" );
});
谁能告诉我如何让它工作?
像
一样使用Event对象的target
属性
$("#lightbox").click(function(e) {
if(e.target.tagName != 'IMG'){
$("#lightbox").css( "display", "none" );
}
});
更新
only if you click the id itself
然后,检查 target
的 id
$("#lightbox").click(function(e) {
if(e.target.id == 'lightbox'){
$("#lightbox").css( "display", "none" );
}
});
按照你写的那样做,但改变第一行:
$('#lightbox').find("*").add("#lightbox").click(function (event) {
$(this).is('img') ? event.stopPropagation() : $("#lightbox").css("display","none");});
我要设置显示:none;在 id 上,但前提是您单击 id 本身而不是该 id 中的 img
$(":not('#lightbox img'),#lightbox").click(function() {
$("#lightbox").css( "display", "none" );
});
谁能告诉我如何让它工作?
像
一样使用Event对象的target
属性
$("#lightbox").click(function(e) {
if(e.target.tagName != 'IMG'){
$("#lightbox").css( "display", "none" );
}
});
更新
only if you click the id itself
然后,检查 target
id
$("#lightbox").click(function(e) {
if(e.target.id == 'lightbox'){
$("#lightbox").css( "display", "none" );
}
});
按照你写的那样做,但改变第一行:
$('#lightbox').find("*").add("#lightbox").click(function (event) {
$(this).is('img') ? event.stopPropagation() : $("#lightbox").css("display","none");});