且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用带有单选按钮的 HTML 'label' 标签

更新时间:2023-02-25 07:49:45

label 标签是否与单选按钮一起使用?

Does the label tag work with radio buttons?

是的

如果是这样,你如何使用它?

If so, how do you use it?

与任何其他表单控件相同.

Same way as for any other form control.

你要么给它一个 for 属性来匹配控件的 id,或者你把控件放在 label 元素中.

You either give it a for attribute that matches the id of the control, or you put the control inside the label element.

我想为左列中的每个标签使用标签标签

I'd like to use the label tag for each label in the left column

标签用于一个控件,而不是一组控件.

A label is for a control, not a set of controls.

如果要为一组控件添加标题,请使用

(并给出 到集合中的每个控件).

If you want to caption a set of controls, use a <fieldset> with a <legend> (and give a <label> to each control in the set).

<fieldset>
  <legend> Salutation </legend>
  <label> <input type="radio" name="salutation" value="Mr."> Mr. </label>
  <label> <input type="radio" name="salutation" value="Mrs."> Mrs. </label>
  <!-- etc -->
</fieldset>