Using the HTML 'label' tag with radio buttons

前端 未结 7 545
暗喜
暗喜 2020-12-28 12:07

Does the label tag work with radio buttons? If so, how do you use it? I have a form that displays like this:

First Name: (text field)
Hair Col         


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-28 12:29

    To answer your question: no, you can't connect Salutation to one of the radio buttons. It wouldn't make sense that if you'd click on Salutation, one of the options would be selected. Instead, you can give Mr, Mrs and Miss their own labels, so if someone clicks on one of those words, the corresponding radio button will be selected.

    
    
    
    
    
    
    

    I do think that you could still wrap Salutation inside a element, you just can't use the for attribute. I stand corrected, see the comments below. Although it's technically possible, it's not what was meant for.

提交回复
热议问题