0

我有三个事件处理程序,mouseenter、mouseleave 和 click 如果用户单击“li”,我想停止事件传播以便不执行 mouseleave 处理程序这是我的代码:

$('.list ul li').mouseenter(function()
    {
        $(this).addClass('listItemSelected');
    });   
    $('.list ul li').mouseleave(function()
    {
        $(this).removeClass('listItemSelected');
    });
    $('.list ul li').click(function(b)
    {
        b.stopImmediatePropagation();   
        $('.list ul').removeClass('listItemSelected');
        $(this).addClass('listItemSelected');
    });
4

1 回答 1

0

更新

$('.list ul li').click(function(e)
{
    e.preventDefault();
    $('.list ul').removeClass('listItemSelected');
    // first remove from the rest of the list items then add to clicked
    $('.list ul li').removeClass('listItemClicked');
    $(this).addClass('listItemClicked');
});

使 listItemSelected 与 listItemClicked 相同

于 2013-03-27T18:27:57.723 回答