将标签与class not id的输入关联起来? [英] Associate label to input with class not id?
本文介绍了将标签与class not id的输入关联起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道您可以使用for和id属性将标签与输入相关联。但是,你可以使用一个类而不是一个ID?谢谢
< label for =rooms>房间数量< / label>
< select id =rooms>
< option value =1> 1< / option>
< option value =2> 2< / option>
< option value =3> 3< / option>
< option value =4> 4< / option>
< / select>
解决方案
类不是唯一的如果您希望将标签与输入相关联而不使用ID,则可以隐式将它分配给包括标签内的输入内容:
< label>房间数量
< select name =rooms>
< option value =1> 1< / option>
< option value =2> 2< / option>
< option value =3> 3< / option>
< option value =4> 4< / option>
< / select>
< / label>
I know that you can associate a label with an input using the for and id attributes. However can you use a class and not an id? Thanks
<label for="rooms">Number of rooms</label>
<select id="rooms">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
解决方案
Classes are not unique (you can have multiple elements with the same class), so no.
If you want to associate a label to an input without using ID, you can implicitly assign it by including said input inside of the label:
<label>Number of rooms
<select name="rooms">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</label>
这篇关于将标签与class not id的输入关联起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文