hide()单选按钮*及其* jQuery中的文本标签 [英] hide() radio button *and* its text label in jquery
问题描述
我要回头看一个最近的项目,以解决可访问性问题,并确保所有表单元素都带有标签.将标签文本放入标签中会导致我之前编写的一些混乱代码出现问题.
I am going back over a recent project sorting out accessibility issues and was making sure all form elements had labels. Putting the label text into a tag caused a problem with some kludgy code I had written before.
基本上,如果您有一个单选按钮及其标签:
Basically, if you have a radio button and its label:
<label for="zone_r1"><input type="radio" name="zone" id="zone_r1" value="NY" />New York</label>
然后您使用jquery将其隐藏,如下所示:
And you use jquery to hide it like so:
$('#zone_r1').hide();
实际按钮被隐藏,但标签文本未被隐藏.最初,我为标签文本设置了一个跨距,然后将其隐藏起来,如下所示:
The actual button is hidden but not the label text. Originally I made a span for the label text and hid that like so:
<input id="NY" type="radio" name="zone" value="NY" /><span id="nyTXT">New York</span>
和
$('#NY').hide();
$('#nyTXT').hide();
有什么想法吗?我更喜欢不使用kludge,它可能无法使用标签中的跨度进行验证,但是也许我太过热情了.
Any ideas? I prefer not to use the kludge and it may not validate with the span in the label, but maybe I am being overly zealous.
推荐答案
$('#zone_r1').parent().hide();
为我工作
这篇关于hide()单选按钮*及其* jQuery中的文本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!