function init() {
const formSelect = document.querySelectorAll('.form-select')[0];
const sizeFormSelect = document.querySelectorAll('.form-select')[1];
formSelect.addEventListener('change', function (e) {
const newOptions = document.createElement('option');
if (e.target.value === '셔츠') {
sizeFormSelect.classList.remove('form-hide');
} else if (e.target.value === '모자') {
sizeFormSelect.classList.add('form-hide');
} else if (e.target.value === '바지') {
sizeFormSelect.classList.remove('form-hide');
sizeFormSelect.innerHTML = '';
newOptions.innerHTML = '<option>29</option> <option>30</option>';
sizeFormSelect.appendChild(newOptions);
}
});
}
init();
위 와 같이 코드를짯는데 바지를 선택하면
29
30
이런식으로 select가 각각나와야하는데 사진처럼 나옵니다.
혹시 스크립트를 어떤식으로 고쳐줘야할까요?..