반응형
250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
Tags
- AWS CI/CD 구축하기
- chartjs
- redis
- Flux
- IntelliJ
- Spring Error
- PostgreSQL
- aws
- Jenkins
- codebuild
- VPN
- kubeflow
- SQL
- COALESCE
- java bigdecimal
- or some instances in your deployment group are experiencing problems.
- codedeploy error
- JavaScript
- Airflow
- aws cicd
- bootstrap
- chart.js
- codedeploy
- 도커
- Python
- Kafka
- codepipeline
- node
- Spring
- docker
Archives
- Today
- Total
Small Asteroid Blog
[jquery] select 선택에 따라 두번째 select 변경하기 본문
728x90
첫번째 select 선택시 두번째 select 내용 변경하기
<script type="text/javascript">
$(document).ready(function () {
var sel1 = {"":'선택',"뉴스":"뉴스","논문":"논문"}
var sel2_1 = {"기후변화":'기후변화',"기후":"기후","온난화":"온난화"}
var sel2_2 = {"논문기후변화":'논문기후변화',"논문기후":"논문기후","논문온난화":"논문온난화"}
//option 호출
function setOption(maparr, selected){
var html = '';
var keys = Object.keys(maparr);
for(var i in keys){
html += "<option value='"+keys[i] + "'>" + maparr[keys[i]] + "</option>";
}
$("select[id='"+selected+"']").html(html);
}
$("select[id='sel1']").on("change",function(){
var option = $("#sel1 option:selected").val();
var subSelName = '';
if(option == "뉴스"){
subSelName = "sel2_1";
}else if(option == "논문"){
subSelName = "sel2_2";
}else{
$("#sel2").hide();
return;
}
$("#sel2").show();
setOption(eval(subSelName), "sel2");
console.log("nn > "+subSelName);
});
setOption(sel1, "sel1");
});//document
</script>
<select id="sel1" name="sel1"></select>
<select id="sel2" name="sel2" style="display: none"></select>
첫번째 select 선택에 따라 두번째 select 내용이 변경됨을 확인할 수 있다.


728x90
반응형
'백엔드 > Spring' 카테고리의 다른 글
[Java] 구글 뉴스 날짜별로 크롤링하기 (0) | 2021.11.08 |
---|---|
element is not attached to the page document (0) | 2021.11.04 |
[Java] 자바 문자열에서 숫자 추출하기 (0) | 2021.10.27 |
Java Selenium 페이지 이동 (크롤링하기) (0) | 2021.10.27 |
[spring error] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception (0) | 2021.10.26 |