我想选择没有ul li
类
.roundabout-in-focus
项
$("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'});
});
但警报永远不会被触发(并且有物品);
实际上,如果我:
alert($('li:not(.roundabout-in-focus)').length);
输出:3
任何想法为什么?
答案 0 :(得分:2)
可能有另一个处理程序停止传播事件。试试这个:
$("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'});
}
});