Input attributes that can have the same “name”

前端 未结 7 700
野的像风
野的像风 2020-12-10 14:12

I noticed that if you have a couple of radios together, you are required to make the name attribute identical on all of them in order for the radios to work as expected:

7条回答
  •  庸人自扰
    2020-12-10 14:40

    Is the radio input the only input type where you can have duplicate name attributes

    No. Any form control can share a name with any other form control.

    This is particularly useful for checkboxes (it allows you to say "Pick any number of these" and then loop over the results on the server without having to hard code a different name for each item.) and submit buttons (it lets you tell which one was clicked without looping over all possible names).

    (and required to do so)?

    Yes. Only radio buttons get special behaviour based on shared names.

提交回复
热议问题