Difference between id and name attributes in HTML

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

    The id will give an element a id, so once you write real code, (like JavaScript) you can use the id to read elements. The name is just a name so the user can see the name of the element, I guess.

    Example:

    text

    //You can also use something like this:
    document.getElementById("heading").value; //Reads the value of the selected element.
    

    Is it helpful? Let me know if there is some problems.

提交回复
热议问题