Programing

readonly =“true”와 readonly =“readonly”의 차이점은 무엇입니까?

lottogame 2020. 11. 23. 07:37
반응형

readonly =“true”와 readonly =“readonly”의 차이점은 무엇입니까?


차이점은 무엇입니까?

<input name="TextBox1" type="text" id="TextBox1" readonly="true" />

과:

<input name="TextBox1" type="text" id="TextBox1" readonly="readonly" />

내가 설정 한 경우 readonlytrue그것은 다소 차이가 작동합니다 readonly='readonly'. W3C 표준은 말한다 readonly해야 'readonly'및 없습니다 'true'. 대부분의 브라우저가 readonly='true'어떤 기능이 약간 다른 것을 허용 하는 이유는 무엇 readonly='readonly'입니까?


요소에 속성 readonly을 부여하면 해당 요소에 읽기 전용 상태가 부여됩니다. 그 뒤에 어떤 값을 입력하든 그 뒤에 값을 입력해도 여전히 읽기 전용으로 간주됩니다. 퍼팅 readonly="false"이 작동하지 않습니다.

W3C 표준을 사용하는 것이 readonly="readonly"좋습니다.


이것은 값 속성이 아닌 속성 설정입니다.

이러한 속성 설정 은보기 당 값이며 할당 할 필요가 없습니다. 존재하는 경우 요소는이 부울 속성을로 설정하고 true, 부재하는 경우 false.

<input type="text" readonly />

실제로 그들에게 가치를 할당하는 것은 자유로운 브라우저입니다. 값을 할당하면 무시됩니다. 브라우저는 특정 속성의 존재 만보고 할당하려는 값을 무시합니다.

물론 일부 프레임 워크는 그와 함께 가치를 제공하지 않고는 이러한 속성을 추가 할 수 없기 때문에 이것은 좋습니다. Asp.net MVC Html 도우미가 그중 하나입니다. jQuery는 속성 개념을 추가 한 버전 1.6까지 동일했습니다.

물론 XML의 속성이 올바른 형식을 갖추려면 값이 필요하기 때문에 XHTML과 관련된 몇 가지 의미가 있습니다. 그러나 그것은 다른 이야기입니다. 따라서 브라우저는 값 할당을 무시해야합니다.

어쨌든. 이름의 철자가 정확하면 브라우저에서 감지 할 수 있는 한 값을 할당하는 것은 신경 쓰지 마십시오 . 그러나 가독성과 유지 관리를 위해 다음과 같이 의미있는 값을 할당하는 것이 좋습니다.

readonly="true" <-- arguably best human readable
readonly="readonly"

반대로

readonly="johndoe"
readonly="01/01/2000"

향후 개발자가 코드를 유지 관리하는 데 혼란을 줄 수 있으며 이러한 속성 설정에 대해보다 엄격한 규칙을 정의 할 수있는 향후 사양을 방해 할 수 있습니다.


readonly="true"이다 무효 HTML5는 , 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>더 짧기 때문에 사용 하십시오.


readonly="readonly"XHTML 구. xhtml에서는 부울 속성이 이렇게 작성됩니다. xhtml에서는 '속성 최소화'( <input type="checkbox" checked>)가 허용되지 않으므로 이것이 xhtml에 부울 속성을 포함하는 유효한 방법입니다. 자세한 내용은 이 페이지참조하십시오 .

귀하의 경우 문서 유형이 전환 또는 엄격한 XHTML을하고 당신이 그것을 확인하려면, 사용 readonly="readonly, 그렇지 않으면 readonly충분하다.


기능적으로 어떻게 다른지 잘 모르겠습니다. 내 현재 OS X 브라우저 배치에는 차이가 없습니다.

I would assume they are all functionally the same due to legacy HTML attribute handling. Back in the day, any flag (Boolean) attribute need only be present, sans value, eg

<input readonly>
<option selected>

When XHTML came along, this syntax wasn't valid and values were required. Whilst the W3 specified using the attribute name as the value, I'm guessing most browser vendors decided to simply check for attribute existence.


According to HTML standards, the use of

<input name="TextBox1" type="text" id="TextBox1" readonly/>

is enough to make the input element readonly. But, XHTML standard says that the usage listed above is invalid due to attribute minimization. You can refer to the links below:

https://www.w3.org/TR/xhtml1/diffs.html#h-4.5

http://www.w3schools.com/tags/att_input_readonly.asp

참고URL : https://stackoverflow.com/questions/6172911/what-is-the-difference-between-readonly-true-readonly-readonly

반응형