본문 바로가기
front/html,Js,타임리프

id와 name의 차이점

by Ms.Pudding 2022. 1. 8.

id값의 특징

id는 html에서 쓸 수 있는 유일한 값을 말합니다.

모든 id는 유니크해야하며 복수로 쓸 수 없습니다.

css에서 #를 써서 사용 가능하다.

 

name값의 특징

view에서 서버에 전송하는 요청에 사용됩니다.

id 속성과 달리 고유하지 않을 수 있습니다.

 

name의 특성은 다음 요소에서만 유효합니다.

<button>, <fieldset>, <form>, <iframe>, <input>, <map>, <meta>,

<object>, <output>,

<param>, <select>, and <textarea>

 

여기서 보다시피 , id값은 고유하기 때문에 한번씩 주고 , name은 여러번 줄 수 있다.

그리고 name은 view를 서버에 보낼 때 쓰기 때문에 name에 있는 변수는 controller에 있는 변수랑 이름을 같게 한다.

 

출처

https://www.w3docs.com/snippets/html/what-is-the-difference-between-the-id-and-name-attributes.html

'front > html,Js,타임리프' 카테고리의 다른 글

자바스크립트 forEach()반복문  (0) 2022.01.15
자바스크립트에서 $는 무슨 뜻일까?? (DOM)  (0) 2022.01.15
input type = "hidden"  (0) 2022.01.08
<td>태그의 cosplan속성  (0) 2022.01.08
label for 의 속성  (0) 2022.01.08

댓글