html
<select onchange="onChangeSelect(this)" id="selectBox">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
javascript
const onChangeSelect = (_selectBox) => {
const selectBox = document.querySelector("#selectBox");
// selectBox 혹은 _selectBox로 셀렉트박스에 접근합니다.
const currentOption = selectBox.options[selectBox.selectedIndex];
console.log(currentOption);
}
'Front-end > JS tip' 카테고리의 다른 글
| javascript 카카오 공유하기 (0) | 2022.01.22 |
|---|---|
| javascript .replaceAll 안될 때 (0) | 2022.01.20 |
| javascript selectbox option 값 구하기 (0) | 2022.01.12 |
| DOM Node, Element 활용 (0) | 2022.01.10 |
| javascirpt object 자르기, index 제한 (0) | 2022.01.05 |