<span>
<img src="img/icon.png" alt="" />
<label><input type="radio" name="" /> Label here</label>
</span>
我希望整个 <span>
都是可点击的,而不仅仅是无线电输入.我如何用 jQuery 做到这一点?
I want the whole <span>
to be clickable, not just the radio input. How do I do it with jQuery?
这是一个更好的方法.
$('span').click(function() {
$(this).find('input').attr({checked:"checked"});
});
请记住,您正在向所有跨度添加点击事件.最好在跨度上有一个类并引用它.
Just keep in mind that you are adding a click event to all spans. Better would be to have a class on the span and reference that.
$('.myClickySpan')...
<span class='myClickySpan'>...