선택 및 선택의 어떤 값이 거짓입니까?
W3 사양에 따르면
<input type="checkbox" checked="checked" />
과
selected="selected"
그러나 대부분의 브라우저는 "CHECKED"라고 작성하고 값을주지 않습니다. 그렇다면 속성을 포함하면 (일관되게) 거짓으로 간주되는 값이 있습니까?
확인란이 선택 취소되는 원인이되는 값 이 없습니다 . checked
속성이있는 경우 설정 한 값에 관계없이 확인란이 선택됩니다.
<input type="checkbox" checked />
<input type="checkbox" checked="" />
<input type="checkbox" checked="checked" />
<input type="checkbox" checked="unchecked" />
<input type="checkbox" checked="true" />
<input type="checkbox" checked="false" />
<input type="checkbox" checked="on" />
<input type="checkbox" checked="off" />
<input type="checkbox" checked="1" />
<input type="checkbox" checked="0" />
<input type="checkbox" checked="yes" />
<input type="checkbox" checked="no" />
<input type="checkbox" checked="y" />
<input type="checkbox" checked="n" />
모든 최신 브라우저 (FF3.6, Chrome 10, IE8)에서 확인 된 모든 것을 렌더링합니다.
checked
및 selected
속성은 속성 이름의 복사 및 빈 문자열 (이후 HTML 5) 만 두 값을 사용할 수 있습니다. 다른 값을 제공하는 것은 오류입니다.
속성을 설정하지 않으려면 전체 속성을 생략해야합니다.
에 있습니다 HTML 4 당신이 값을 제외한 모든 것을 생략 할 수 있습니다. HTML 5 는 이름을 제외한 모든 것을 생략하도록 변경했습니다 (실제적인 차이는 없습니다).
따라서 속성의 유효한 표현 집합 (cAsE의 변형 제외)은 다음과 같습니다.
<input ... checked="checked"> <!-- All versions of HTML / XHTML -->
<input ... checked > <!-- Only HTML 4.01 and earlier -->
<input ... checked > <!-- Only HTML 5 and later -->
<input ... checked="" > <!-- Only HTML 5 and later -->
text / html (HTML 또는 XHTML)로 제공되는 문서는 태그 수프 파서를 통해 공급되며 확인 된 속성 (모든 값 포함)의 존재는 "이 요소를 확인해야 함"으로 처리됩니다. 따라서, 유효하지 않은 반면 checked="true"
, checked="yes"
및 checked="false"
모든 트리거 체크 상태입니다.
속성에 다른 값이 주어지면 XML 구문 분석 모드에 어떤 오류 복구 메커니즘이 있는지 알아 내려는 경향이 없었지만 HTML 및 / 또는 간단한 오류 복구의 레거시가이를 처리 할 것으로 예상 합니다. 같은 방식으로 : 속성이 있으면 요소가 검사됩니다.
(그리고 위의 모든 동일하게 적용 selected
이에처럼 checked
.)
false로 간주되는 값은 없으며 속성이없는 경우에만 해당됩니다. 그러나 유효하지 않은 값이 많이 있으며 일부 구현에서는 특정 유효하지 않은 값을 false로 간주 할 수 있습니다.
HTML5 사양
http://www.w3.org/TR/html5/forms.html#attr-input-checked :
비활성화 된 콘텐츠 속성은 부울 속성입니다.
http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes :
요소에 부울 속성이 있으면 참 값을 나타내고 속성이 없으면 거짓 값을 나타냅니다.
속성이있는 경우 해당 값은 선행 또는 후행 공백없이 속성의 표준 이름에 대해 ASCII 대소 문자를 구분하지 않는 일치 값이거나 빈 문자열이어야합니다.
결론
다음은 유효하고 동등하며 참입니다 .
<input type="checkbox" checked />
<input type="checkbox" checked="" />
<input type="checkbox" checked="checked" />
<input type="checkbox" checked="ChEcKeD" />
다음은 유효하지 않습니다 .
<input type="checkbox" checked="0" />
<input type="checkbox" checked="1" />
<input type="checkbox" checked="false" />
<input type="checkbox" checked="true" />
속성이없는 것은 false에 대한 유일한 유효한 구문입니다 .
<input type="checkbox" />
추천
If you care about writing valid XHTML, use checked="checked"
, since <input checked>
is invalid and other alternatives are less readable. Else, just use <input checked>
as it is shorter.
Actually, the HTML 4.01 spec says that these attributes do not require values. I haven't personally encountered a situation where providing a value rendered these controls as unselected.
Here are the respective links to the spec document for selected and checked.
Edit: Firebug renders the checkbox as checked regardless of any values I put in quotes for the checked attribute (including just typing "checked" with no values whatsoever), and IE 8's Developer Tools forces checked="checked". I'm not sure if any similar tools exist for other browsers that might alter the rendered state of a checkbox, however.
The empty string is false as a rule.
Apparently the empty string is not respected as empty in all browsers and the presence of the checked attribute is taken to mean checked. So the entire attribute must either be present or omitted.
ReferenceURL : https://stackoverflow.com/questions/4228658/what-values-for-checked-and-selected-are-false
'programing' 카테고리의 다른 글
동일한 메서드 서명으로 게시 및 가져 오기 (0) | 2021.01.17 |
---|---|
활동이 시작될 때 소프트 키보드 표시 (0) | 2021.01.17 |
원격 지점에서 병합하기 전에 실제 git diff를 확인하는 방법은 무엇입니까? (0) | 2021.01.17 |
Android-WebView의 로컬 이미지 (0) | 2021.01.17 |
Ajax 호출이 Selenium 2 WebDriver로 완료 될 때까지 기다립니다. (0) | 2021.01.17 |