单击LI时单击链接

San*_*man 3 javascript jquery

好的,我使用了这个列表布局,我希望列表行在我悬停时突出显示.现在,这不是一个真正的问题,因为我可以使用JavaScript来更改类的例子,但我希望光标悬停和点击时,我想跟进中的链接时,更改为指针.

示例代码可以在这里找到:

http://sandman.net/test/hover_links.html

我还想在其中包含符合条件的链接时突出​​显示LI.最好使用jQuery ...任何想法?

-

我编辑了代码以包含下面的建议,问题是当我点击LI中的其他项目时,click()动作会触发...

-

是的,所以现在我编辑了代码.我添加了一个类应遵循上点击链接(或多个),然后event.stopPropagation()上不具有这个类的联系,所以他们被浏览器相应handeled.

再次感谢!

Jam*_*mes 7

jQuery('li:has(a)')
    .css('cursor', 'pointer')
    .hover(function(){
        jQuery(this).addClass('highlight');
    }, function(){
        jQuery(this).removeClass('highlight');
    })
    .click(function(e){
        if (e.target === this) {
            window.location = jQuery('a', this).attr('href');
        }
    });
Run Code Online (Sandbox Code Playgroud)