问题描述
我正在回顾最近的一个项目,以解决可访问性问题,并确保所有表单元素都有标签.将标签文本放入标签会导致我之前编写的一些笨拙的代码出现问题.
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,它可能无法通过标签中的 span 进行验证,但也许我过于热心了.
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();
为我工作
这篇关于隐藏()单选按钮*和*它在jquery中的文本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!