如何只定位li项目而不是其中的单选按钮

时间:2016-10-12 12:29:28

标签: jquery jquery-selectors css-selectors

我在UL中有列表项。我想点击一个特定的列表项并执行一次单击,但是li里面有一个单选按钮,当我点击它时,单击偶数也会触发。我如何定位li项目而不是其中的无线电。我尝试使用:not selector,它确实做到了。任何帮助,将不胜感激。 谢谢。

<li>
    <h5><a class="tooltiptext" href="show">Click</a></h5>
    <label for="itemA">
        <img src="images/templates/template1.png"></img>
    </label><br />
    <input type="radio" id="itemA" class="chooseItem" name="chooseTemplate" value="itemA" checked>
    Select
</li>
$("li:nth-child(1):not(input[type='radio']").click(function(e){
})

它可以工作,但是当我点击收音机时,我不想触发点击事件。

2 个答案:

答案 0 :(得分:3)

你可以这样做。

 $("li:nth-child(1)").click(function(e){
     if(!$(e.target).is(':radio')) {
         //you code goes here
     }
 })

答案 1 :(得分:2)

检查事件的目标不是广播或其相关标签,因为点击标签会改变广播状态

$("li:nth-child(1)").click(function(e){
   if(!$(e.target).is('label[for], :radio') ){
      // not a radio click heree
   }
})