일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 리눅스
- 델파이 기법
- 키보드 이벤트
- 정보처리기사
- 모듈화
- javascript
- 서버
- S-HTTP
- 정처기
- 트리거
- 브레인스토밍
- 인스펙션
- input
- 정처기 실기
- EAI
- 소프트웨어
- 비동기
- 워크스루
- SSL/TLS
- rest
- 인터페이스
- 프로시저
- 자바스크립트
- esb
- 모듈
- 형상관리
- 동기
- 라디오 버튼
- 정보처리기사 실기
- Ajax
- Today
- Total
방구석 상상코딩
[HTML] select 박스 값 가져오기 본문
select 태그 생성
<select>
<option value="값1">값1</option>
<option value="값2">값2</option>
<option value="값3">값3</option>
</select>
1) 선택된 값 확인
- id로 선택
$("[#select박스id] option:selected").val();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <select id="userListSB"> <option value="홍길동">홍길동</option> <option value="조석">조석</option> <option value="아무개">아무개</option> </select> <button type="button" id="selectbutton">값 가져오기</button> <script> $(document).ready(function () { $('#selectbutton').click(function () { var select = $("#userListSB option:selected").val(); console.log(select); }); }); </script> | cs |
- name로 선택
$("select[name=select박스name]").val();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <select name="userListname"> <option value="홍길동">홍길동</option> <option value="조석">조석</option> <option value="아무개">아무개</option> </select> <button type="button" id="selectbutton">값 가져오기</button> <script> $(document).ready(function () { $('#selectbutton').click(function () { //var select = $("#userListSB option:selected").val(); var select = $("select[name=userListname]").val(); console.log(select); }); }); </script> | cs |
2) 기본값 지정
See the Pen select box 1 by Dorad (@doradji) on CodePen.
3) 비활성화
<select disabled>
<option value="값2" disabled>값2</option>
</select>
See the Pen select box 2 by Dorad (@doradji) on CodePen.
4) 특정 option 목록에서 숨기기
<select>
<option value="값2" hidden>값2</option>
</select>
See the Pen select box 3 by Dorad (@doradji) on CodePen.
5) 변화에 따른 val값 가져오기
See the Pen chane selectbox by Dorad (@doradji) on CodePen.
6) option 강제로 선택하기
- selectedIndex 사용
document.getElementById("selectbox").selectedIndex ="3"; // 값3
var selectId = $("#selectbox option:selected").val();
- option value값으로 선택하기
var select2 = $("#selectbox").val("값2").prop("selected", true); // 값2
- option 순서로 선택하기
var select = $("#selectbox option:eq(1)").prop("selected", true); // 값1
See the Pen select box 강제로 선택하기 by Dorad (@doradji) on CodePen.
https://java119.tistory.com/27
[jQuery] select box 선택값 가져오기,value 값 여러 개 가져 오기
Select box ID로 접근하여 선택된 값 읽기 홍길동 조석 아무개 $("#userListSB option:selected").val(); Select box ID로 접근하여 선택된 텍스트 읽기 $("#userListSB option:selected").text(); //홍길동,조석,..
java119.tistory.com
[HTML] select 태그(박스) 사용방법
select 태그를 사용한 방식과 콤보박스라 불리는 좀 더 기능적 특징을 가진 UI로 구분할 수 있습니다. 오늘은 select 태그를 사용한 방법에 대하여 예제와 함께 알아보도록 하겠습니다.
webisfree.com
https://hianna.tistory.com/322
[HTML] 콤보박스(select) (1) - 기본값 지정, 비활성화, 항목 비활성화
사용자로부터 선택 입력을 받을 수 있는 콤보박스(드롭다운 박스)를 만드는 방법을 알아보도록 하겠습니다. 기본 콤보박스 만들기 See the Pen select by anna (@hianna) on CodePen. HTML에서 콤보박..
hianna.tistory.com
[jQuery] Select박스 option 값 선택하기
1. option value값으로 선택하기 $("#id").val("1").prop("selected", true); //값이 1인 option 선택 2. option 순서로 선택하기 $("#id option:eq(0)").prop("selected", true); //첫번째 option 선택
yjcorp.tistory.com
'Spring Boot > JavaScript' 카테고리의 다른 글
정규표현식(Regular Expression) (0) | 2022.02.04 |
---|---|
[jQuery] check 박스 값 가져오기 (0) | 2022.01.24 |
[Javascript / jQuery] input Radio Button 값 가져오기/설정하기 (0) | 2022.01.22 |
[HTML] input 태그 종류 (0) | 2022.01.18 |
[JavaScript / jQuery] input text 값 가져오기/설정하기 (0) | 2022.01.18 |