입력 텍스트 요소에 대한 올바른 읽기 전용 속성 구문은 무엇입니까?
대부분의 경우에 대한 readonly
속성에 익숙 text input
하지만 다른 웹 사이트에서 코드를 읽는 동안 (나의 불쾌한 습관)이 속성에 대한 구현을 두 개 이상 보았습니다.
<input type="text" value="myvalue" class="class anotherclass" readonly >
과
<input type="text" value="myvalue" class="class anotherclass" readonly="readonly" >
그리고 나는 본 적도있다
<input type="text" value="myvalue" class="class anotherclass" readonly="true" >
.. 그리고 더 많이 본 것 같지만 지금은 정확한 구문이 기억 나지 않습니다 ..
그래서, 내가 사용해야 할 올바른 것은 무엇입니까?
에서 W3 :
readonly = "readonly" 또는 ""(빈 문자열) 또는 비어 있음 -요소가 값을 편집 할 수없는 컨트롤을 나타내도록 지정합니다.
그래서 기본적으로 동일합니다.
HTML5 사양 :
http://www.w3.org/TR/html5/forms.html#attr-input-readonly :
읽기 전용 속성은 부울 속성입니다.
http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes :
요소에 부울 속성이 있으면 참 값을 나타내고 속성이 없으면 거짓 값을 나타냅니다.
속성이있는 경우 해당 값은 선행 또는 후행 공백없이 속성의 표준 이름에 대해 ASCII 대소 문자를 구분하지 않는 일치 값이거나 빈 문자열이어야합니다.
결론 :
다음은 유효하고 동등하며 참입니다 .
<input type="text" readonly />
<input type="text" readonly="" />
<input type="text" readonly="readonly" />
<input type="text" readonly="ReAdOnLy" />
다음은 유효하지 않습니다 .
<input type="text" readonly="0" />
<input type="text" readonly="1" />
<input type="text" readonly="false" />
<input type="text" readonly="true" />
속성이없는 것은 false에 대한 유일한 유효한 구문입니다 .
<input type="text"/>
추천
유효한 XHTML 작성에 관심이 있다면를 사용하십시오 readonly="readonly"
. <input readonly>
는 유효하지 않으며 다른 대안은 읽기가 어렵 기 때문입니다. 그렇지 않으면 <input readonly>
더 짧기 때문에 사용 하십시오.
이어야한다
<input type="text" value="myvalue" class="class anotherclass" readonly="readonly" />
'IT TIP' 카테고리의 다른 글
powershell을 사용하여 레지스트리 키의 값과 값만 가져 오는 방법 (0) | 2020.11.26 |
---|---|
jQuery AJAX 호출에서 '최종'과 유사한 것이 있습니까? (0) | 2020.11.26 |
Dart 프로그램을 "수면"하려면 어떻게해야합니까? (0) | 2020.11.26 |
npm 오류! (0) | 2020.11.26 |
원본 어셈블리를 신뢰할 수 없기 때문에 MSTest 실행이 실패합니다. (0) | 2020.11.26 |