Difference between id and name attributes in HTML

前端 未结 19 3327
感动是毒
感动是毒 2020-11-22 05:17

What is the difference between the id and name attributes? They both seem to serve the same purpose of providing an identifier.

I would lik

19条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 05:55

    The name attribute is used when sending data in a form submission. Different controls respond differently. For example, you may have several radio buttons with different id attributes, but the same name. When submitted, there is just the one value in the response - the radio button you selected.

    Of course, there's more to it than that, but it will definitely get you thinking in the right direction.

提交回复
热议问题