2010-01-13 81 views
0

当用户点击LI的空白区域时,我有兴趣让我的LI切换。在LI确实包含重定向链接,但在情况下,当用户点击LI的空白区域,我想的LI切换JQUERY,当点击LI并且点击不在时<A href>切换

<li id="58" class="records"> 
<a href="adadad">Title</a> 
<div class="expanded" style="display:none;" id="expanded_58"> STUFF </DIV> 
</li> 

实施例,与上面的代码中,如果用户点击LI,并且该点击不在HREF上,我想将expanded_58改为Toggle。

谢谢!

回答

2
$("li.records").click(function(e){ 
    if (e.target.nodeName == "LI") 
    $(".expanded", this).toggle(); 
}); 
3

使用此:

$(function(){ 
    $('li.records').click(function(e){ 
     if(e.target == this) $('div.expanded', this).toggle(); 
    }); 
});