2013-02-14 68 views
0

所以,我有一个网站,从左到右滚动使用箭头键。我也有一个灯箱,它也使用箭头键浏览每个图像。有没有办法让功能在灯箱被追加时不会触发?如何禁用功能,如果文件包含元素

是这样的:

$('body').keydown(function(e) { 
    if(e.keyCode == 37) { 
if ($("body").has("#lightbox").length< 0) { do nothing } 
else { 
    { 
    do something 
    } 
    }); 

是明确的:元素#lightbox将只存在/被灯箱触发元素之后追加已被点击

+0

你写的东西有问题吗? – 2013-02-14 00:40:51

+0

so call preventDefault – epascarello 2013-02-14 00:42:39

+0

'length'永远不会小于零 – charlietfl 2013-02-14 00:42:58

回答

0
$('body').keydown(function(e) { 
    if(e.keyCode == 37) { 
if ($("body").has("#lightbox").length > 0) { do something } 
else { 
{ 
do nothing 
} 
}); 

相关问题