The code copy is as follows:
<select id = "cityList" >
<select id = "selectId" >
<option value = "0">0th</option>
</select>
<script>
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 methods through id (you can also add methods through objects)
selectId.onchange = function(){
// Get value and text through object
alert(selectObj.value);
alert(selectObj.options[selectObj.selectedIndex].text);
// Get value and text through 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);
};
</script>