How do I programmatically set the value of a select box element using JavaScript?

后端 未结 17 1664
轮回少年
轮回少年 2020-11-22 06:33

I have the following HTML

17条回答
  •  囚心锁ツ
    2020-11-22 06:51

    You can use this function:

    selectElement('leaveCode', '11')
    
    function selectElement(id, valueToSelect) {    
        let element = document.getElementById(id);
        element.value = valueToSelect;
    }
    

提交回复
热议问题