Difference between id and name attributes in HTML

前端 未结 19 3162
感动是毒
感动是毒 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:58

    The way I think about it and use it is simple:

    id is used for CSS and JavaScript/jQuery (has to be unique in a page)

    name is used for form handling in PHP when a form is submitted via HTML (has to be unique in a form - to some extent, see Paul's comment below)

提交回复
热议问题