Difference between id and name attributes in HTML

前端 未结 19 2880
感动是毒
感动是毒 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条回答
  •  旧时难觅i
    2020-11-22 05:53

    If you're not using the form's own submit method to send information to a server (and are instead doing it using javascript) you can use the name attribute to attach extra information to an input - rather like pairing it with a hidden input value, but looks neater because it's incorporated into the input.

    This bit does still currently work in Firefox although I suppose in the future it might not get allowed through.

    You can have multiple input fields with the same name value, as long as you aren't planning to submit the old fashioned way.

提交回复
热议问题