hover不能做事件委託

動態生成的元素做事件委託
正確寫法:

$(document.body).on('mouseenter',"#newslist li:not(:first)",function(e){
    $(this).css("background-color","#EC4413");
    $(this).children().css("color","#ffffff");
 });
$(document.body).on('mouseout',"#newslist li:not(:first)",function(e){
     $(this).css("background-color","#eeeeee");
     $(this).children().css("color","#333333");
});

錯誤寫法:

$("#newslist li:not(:first)").hover(
    function(){
        $(this).css("background-color","#EC4413");
        $(this).children().css("color","#ffffff");
    },
    function(){
        $(this).css("background-color","#eeeeee");
        $(this).children().css("color","#333333");
    }
);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章