我想选择所有没有.roundabout-in-focus
类别的ul li
项目
$("ul").delegate("li.roundabout-in-focus", "click", function() {
$(this).css({position:'absolute',height:'300px',width:'400px',left:'50px',top:'-50px'});
$(this).find('img').hide();
$(this).find('iframe').css({'visibility':'visible'});
});
$("ul").delegate("li:not(.roundabout-in-focus)", "click", function() {
/* $('.roundabout-in-focus').css({position:'absolute',height:'300px',width:'400px',left:'120px',top:'-20px'});*/
alert('hey');
$('.roundabout-in-focus').find('img').show();
$('.roundabout-in-focus').find('iframe').css({'visibility':'hidden'});
});
但警报从未触发(并且有项);
实际上是,如果i:
alert($('li:not(.roundabout-in-focus)').length);
输出:3
知道为什么吗?
可能有另一个处理程序正在停止事件的传播。试试这个:
$("ul").delegate("li", "click", function() {
if($(this).hasClass("roundabout-in-focus")) {
$(this).css({position:'absolute',height:'300px',width:'400px',left:'50px',top:'-50px'});
$(this).find('img').hide();
$(this).find('iframe').css({'visibility':'visible'});
} else {
/* $('.roundabout-in-focus').css({position:'absolute',height:'300px',width:'400px',left:'120px',top:'-20px'});*/
alert('hey');
$('.roundabout-in-focus').find('img').show();
$('.roundabout-in-focus').find('iframe').css({'visibility':'hidden'});
}
});