如何仅针对 li 项目而不是其中的单选按钮
How to target only li item and not radio button inside it
我在 UL 中有列表项。我想单击一个特定的列表项并执行一次单击,但是 li 中有一个单选按钮,当我也单击它时,单击甚至被触发。我如何定位 li 项目而不是其中的收音机。我尝试使用 :not 选择器,它确实起到了作用。任何帮助,将不胜感激。
谢谢。
<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){
})
它有效,但是当我点击收音机时我不想触发点击事件。
你可以像下面那样做。
$("li:nth-child(1)").click(function(e){
if(!$(e.target).is(':radio')) {
//you code goes here
}
})
检查事件的目标不是收音机或其关联标签,因为单击标签会更改收音机状态
$("li:nth-child(1)").click(function(e){
if(!$(e.target).is('label[for], :radio') ){
// not a radio click heree
}
})
我在 UL 中有列表项。我想单击一个特定的列表项并执行一次单击,但是 li 中有一个单选按钮,当我也单击它时,单击甚至被触发。我如何定位 li 项目而不是其中的收音机。我尝试使用 :not 选择器,它确实起到了作用。任何帮助,将不胜感激。 谢谢。
<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){
})
它有效,但是当我点击收音机时我不想触发点击事件。
你可以像下面那样做。
$("li:nth-child(1)").click(function(e){
if(!$(e.target).is(':radio')) {
//you code goes here
}
})
检查事件的目标不是收音机或其关联标签,因为单击标签会更改收音机状态
$("li:nth-child(1)").click(function(e){
if(!$(e.target).is('label[for], :radio') ){
// not a radio click heree
}
})