TAG
JavaScript
Result
Run
License
<label><input type="radio" name="filter_cartype" value="alltypes" checked />전체</label> <label><input type="radio" name="filter_cartype" value="lightcar" />경차</label> <label><input type="radio" name="filter_cartype" value="compactsuv" />소형 SUV</label> <select name="car_type"> <optgroup label="경차"> <option value="Ray">Ray</option> <option value="Morning">Morning</option> <option value="Spark">Spark</option> </optgroup> <optgroup label="소형 SUV"> <option value="Kona">Kona</option> <option value="Niro">Niro</option> <option value="Stonic">Stonic</option> </optgroup> </select>
window.addEventListener("load", function() { const $aElCartypes = document.querySelectorAll('input[name="filter_cartype"]'); const $elCarType = document.querySelector('select[name="car_type"]'); $aElCartypes.forEach(el => { el.addEventListener("input", e => { let type = e.currentTarget.value; if(type != "alltypes") $elCarType.selectedIndex = -1; [...$elCarType.children].forEach((elOpt, index, arr) => { elOpt.disabled = false; if(type == "lightcar") arr[1].disabled = true; else if(type == "compactsuv") arr[0].disabled = true; }); }); }); });
Console
expand_less
License
License
by DevDic
Close