jQuery로 select 옵션의 레이블을 가져오는 방법은 무엇입니까?
<select>
<option value="test">label </option>
</select>
값은 다음을 통해 검색할 수 있습니다.$select.val()
.
무엇이 말이야.label
?
IE6에서 작동할 수 있는 솔루션이 있습니까?
사용해 보십시오.
$('select option:selected').text();
안녕하세요, 우선 선발자에게 아이디를 주세요.
<select id=theid>
<option value="test">label </option>
</select>
그런 다음 선택한 레이블을 다음과 같이 부를 수 있습니다.
jQuery('#theid option:selected').text()
참고로 보조 장치도 있습니다.label
옵션 태그의 속성:
//returns "GET THIS" when option is selected
$('#selecter :selected').attr('label');
HTML
<select id="selecter">
<option value="test" label="GET THIS">
Option (also called label)</option>
</select>
드롭다운에서 특정 옵션의 레이블을 가져오려면 다음을 입력합니다.
$('.class_of_dropdown > option[value='value_to_be_searched']').html();
또는
$('#id_of_dropdown > option[value='value_to_be_Searched']').html();
이것이 도움이 되었습니다.
$('select[name=users] option:selected').text()
를 사용하여 셀렉터에 액세스할 때this
키워드
$(this).find('option:selected').text()
사용해 보십시오.
$('select option:selected').prop('label');
두 스타일 모두에 대해 표시된 텍스트를 꺼냅니다.<option>
요소:
<option label="foo"><option>
->"foo"
<option>bar<option>
->"bar"
둘 다 있는 경우label
요소 내부의 속성과 텍스트를 사용합니다.label
속성, 브라우저와 동일한 동작입니다.
후세를 위해, 이것은 jQuery 3.1.1에 따라 테스트되었습니다.
$("select#selectbox option:eq(0)").text()
"option:eq(0)"의 0 인덱스는 검색할 인덱스 옵션과 교환할 수 있습니다.
최신 브라우저에서는 이를 위해 JQuery가 필요하지 않습니다.대신 사용
document.querySelectorAll('option:checked')
또는 다음 대신 DOM 요소를 지정합니다.document
<SELECT id="sel" onmouseover="alert(this.options[1].text);"
<option value=1>my love</option>
<option value=2>for u</option>
</SELECT>
이를 위해 작동하는 플런커를 만들었습니다.https://plnkr.co/edit/vR9aGoCwoOUL9tevIEen $('#console').append("<br/>"+$('#test_s :selected').text())
찾으시는 제품$select.html()
언급URL : https://stackoverflow.com/questions/2175737/how-to-get-label-of-select-option-with-jquery
'programing' 카테고리의 다른 글
호출 워크북을 닫지 않고 VBA SaveAs를 사용하는 방법은 무엇입니까? (0) | 2023.08.08 |
---|---|
상위 div를 기준으로 "위치: 고정" div의 너비 설정 (0) | 2023.08.08 |
스프링 부트 외부 구성 (0) | 2023.08.08 |
초점을 잃었을 때 DOM에서 사라지는 html 요소를 어떻게 검사할 수 있습니까? (0) | 2023.08.08 |
이 오프셋 구현이 작동하는 이유는 무엇입니까? (0) | 2023.08.08 |