Difference between id and name attributes in HTML

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

    Id : 1) It is used to identify the HTML element through the Document Object Model (via Javascript or styled with CSS). 2) Id is expected to be unique within the page.

    Name corresponds to the form element and identifies what is posted back to the server. Example :

    First name:

    The "Last name" field below is outside the form element, but still part of the form.

    Last name:

提交回复
热议问题