委托和:不是(.myClass)不合作

时间:2011-10-06 12:12:26

标签: jquery class delegates event-handling click

我想选择没有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

任何想法为什么?

1 个答案:

答案 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'});
    }
});