简体   繁体   English

JQUERY,当单击一个LI且单击不是在<A href>Toggle上时</a>

[英]JQUERY, When an LI is clicked and the click was not on an <A href> Toggle

I'm interested in having my LIs toggle when a user clicks in the blank area of the LI. 我对用户单击LI的空白区域时切换我的LI感兴趣。 The LI does contain links that redirect, but in the case when the user clicks on a blank area of the LI I would like the LI to toggle LI确实包含重定向的链接,但是在用户单击LI的空白区域的情况下,我希望LI进行切换

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

Example, with the code above, if the user clicks on the LI, and that click isn't on the HREF, I would like the expanded_58 to Toggle. 例如,在上面的代码中,如果用户单击LI,而该单击不在HREF上,我希望expand_58切换。

Thanks! 谢谢!

Use this: 用这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM