更大的无线电选择范围
<span>
<img src="img/icon.png" alt="" />
<label><input type="radio" name="" /> Label here</label>
</span>
我希望整个 都是可点击的,而不仅仅是无线电输入。我如何使用 jQuery 做到这一点?
<span>
<img src="img/icon.png" alt="" />
<label><input type="radio" name="" /> Label here</label>
</span>
I want the whole <span>
to be clickable, not just the radio input. How do I do it with jQuery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,最简单的解决方案是将所有内容包装在
标记内,如下所示:
当您为标签指定
for
属性时,以及相同的id
到字段中,标签变得可点击并将激活相应的输入。但是,如果您出于某种原因需要在 jQuery 中执行此操作,那么这应该可行:
Well, the easiest solution would be to wrap everything inside the
<label>
tag, like this:When you specify an
for
attribute to label, and the sameid
to the field, the label becomes clickable and will activate the corresponding input.But, if you for some reason need to do it in jQuery, this should work:
您可以在没有 jQuery 的情况下完成此操作,只需将
改为
即可:
You could do it without jQuery by just making the
<span>
the<label>
instead:这是一个更好的方法。
请记住,您正在向所有范围添加点击事件。更好的办法是开设一个关于跨度的课程并参考它。
This is a better way.
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.
您似乎没有使用 label< 的
for
属性/a>.也许这样做会对你有所帮助It looks like you're not using the
for
attribute of the label. Maybe doing so will help you我相信应该这样做。
I believe should do it.