var selectObj = document.getElementById('selectId'); // Add option through object selectId.add(new Option("first","1")) selectId.add(new Option("Second", "2")) // Add option by id selectId.add(new Option("Third", "3")) selectId.add( new Option("Fourth", "4")) // Add method through id (you can also add method through object) selectId.onchange = function(){ // Get through object value and text alert(selectObj.value); alert(selectObj.options[selectObj.selectedIndex].text); // Get value and text by id alert(selectId.value) ; alert(selectId.options[selectId.selectedIndex].text); // You can also get value and text through this alert(this.value); alert(this.options[ this.selectedIndex].text); };
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn