zeptojs에서 select에서 선택한option의 값을 가져옵니다.

1280 단어 optionselectzeptojs

첫 번째 방법

// get OPTION elements for which `selected` property is true
$('option').not(function(){ return !this.selected })

문제
:$(‘option[selected]’) only finds options that have their selected attr set in the html.It does not find values the the user has selected themselves.
결론:
This is expected behavior. Such CSS selectors match attribute values, which don’t change with user interaction. Theselected property of the element changes, but attribute doesn’t.

두 번째 방법

$("#ID").val()   value
$("#ID option").eq($("#ID").attr("selectedIndex")).text()     

좋은 웹페이지 즐겨찾기