아핫뉴스실시간 인기검색어
아핫뉴스 화산 이미지
화산 아이콘 11
이재명 대통령, 대한노인회 오찬
아하

생활

생활꿀팁

흰사마귀126
흰사마귀126

html에서 label태그에 대해 간단한 질문이 있습니다.

html에서 아래 그냥 이름과 label태그에 있는 이름의 차이는 무엇인가요?
id값 생성안하고 그냥 저 코드 자체만 봤을때요

<body>
<form>
이름


<label>이름</label>
</form>
</body>

    2개의 답변이 있어요!
    • 프알못
      프알못
      <label for="name">이름 : </label> <input id="name" type="text" />

      <label> 태그의 for 속성으로 클릭했을 때 해당 id의 input을 클릭한 것처럼 되게 할 수 있습니다.

      해당 input이 checkbox인 경우 그 input을 가리키는 label을 누르면 그 체크박스가 체크됩니다!

    • https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_label

      위 사이트에 들어가셔서 보시면

      단순히 동그란 버튼을 누르지 않고 텍스트를 클릭해도 같이 작동하게 해주는 역할을 해줍니다.

      <button>, <input>, <meter>, <output>, <progress>, <select>,<textarea> 요소에 적용이 가능하며

      label태그의 for와 input등의 태그에서 id값이 동일 할 경우 묶어지죠

      <p>Click on one of the text labels to toggle the related control:</p> <label for="male">Male</label> <input type="radio" name="gender" id="male" value="male"><br> <label for="female">Female</label> <input type="radio" name="gender" id="female" value="female"><br> <label for="other">Other</label> <input type="radio" name="gender" id="other" value="other"><br><br>