IT TIP

입력 텍스트 요소에 대한 올바른 읽기 전용 속성 구문은 무엇입니까?

itqueen 2020. 11. 26. 20:35
반응형

입력 텍스트 요소에 대한 올바른 읽기 전용 속성 구문은 무엇입니까?


대부분의 경우에 대한 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" />

참고 URL : https://stackoverflow.com/questions/16109358/what-is-the-correct-readonly-attribute-syntax-for-input-text-elements

반응형