2012-11-06 2 views
8

한 페이지에 여러 개의 양식이 있습니다. 각 양식에는 정확히 동일한 내용이 있습니다. 하지만 내 레이블에 관한 문제가 발생했습니다. 나는 "for"태그 레이블이 고유해야하며 요소 id를 지적해야하지만 어떤 이유로 폼을 곱해야합니다. jsfiddle에있는 내 코드에 my code페이지 발행시 동일한 양식 레이블이 여러 개 있습니다.

<form> 
<label for="option1">Option 1</label> 
<input type="radio" id="option1" name="options"> 

<label for="option2">Option 2</label> 
<input type="radio" id="option2" name="options"> 

<label for="option3">Option 3</label> 
<input type="radio" id="option3" name="options"> 
</form> 

<!-- another form but the same content --> 
<form> 
<label for="option1">Option 1</label> 
<input type="radio" id="option1" name="options"> 

<label for="option2">Option 2</label> 
<input type="radio" id="option2" name="options"> 

<label for="option3">Option 3</label> 
<input type="radio" id="option3" name="options"> 
</form>​ 

감사

을 참조하십시오
+0

'for'는 고유하지 않아도됩니다. 'id'는 않습니다. 동일한 양식 컨트롤을 가리키는 여러 개의 레이블을 가질 수 있습니다. – Quentin

답변

7

다음 중 하나를

  • 는 폼의 지정된 인스턴스에있는 모든 식별자에 적용되는 접두사를 생성
  • for 또는 id을 사용하지 말고 양식 컨트롤 레이블 요소 안에 넣지 마십시오.
관련 문제