728x90
요세 들어 순수하게 Jquery 만 쓰기 보다는 자바 스크립트를 섞어 쓰는 경향이 나타 나는 것 같다.
그래서 구글링을 하다 보니 아래 와 같은 소스를 찾았다.
원문 링크를 걸어 두니 참조 해 보시기 바란다.
아래 에 소스도 적어뒀다.
출처: https://stackoverflow.com/questions/17001961/how-to-add-drop-down-list-select-programmatically
How to add Drop-Down list (<select>) programmatically?
var myParent = document.body;
//Create array of options to be added
var array = ["Volvo","Saab","Mercades","Audi"];
//Create and append select list
var selectList = document.createElement("select");
selectList.id = "mySelect";
myParent.appendChild(selectList);
//Create and append the options
for (var i = 0; i < array.length; i++) {
var option = document.createElement("option");
option.value = array[i];
option.text = array[i];
selectList.appendChild(option);
}
728x90
'자바스크립트' 카테고리의 다른 글
[자바스크립트] Fade In & Fade Out (0) | 2020.09.13 |
---|---|
[JavaScript] Dictionary 사용하는 방법 (0) | 2020.08.22 |
[자바스크립트] 숫자 여부 판단 함수, 숫자인지 문자인지, isNum, isNumeric, isNumber JavaScript (0) | 2020.08.20 |
[JavaScript] String.split() 문자열 분할 하는 메서드 (0) | 2020.08.19 |
자바스크립트 숫자 3자리 마다 콤마 찍기 (2) | 2020.08.17 |