Home > Article > Web Front-end > Javascript operates dom object select (detailed answer)
Below I will bring you a comprehensive analysis of the selection of Javascript operating dom objects. Let me share it with you now and give it as a reference for everyone.
html code:
<select id="university"> <option value="北京大学">北京大学</option> <option value="清华大学">清华大学</option> <option value="北京电影学院">北京电影学院</option> </select>
js native operation
1. Get the select object;
var university=document.getElementById("university");
2. Get the select object The index value of option;
var index=university.selectedIndex;
3. Get the value of option selected by select;
var val=university.options[index];
4. Get the index of the selected option;
var text=university.options[index].text;
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Nodejs Electron ubuntu installation steps detailed explanation
Native JS AJAX Produce three-level linkage effect (with code)
##Vue Video.jsDetailed explanation of the steps to play m3u8 video
The above is the detailed content of Javascript operates dom object select (detailed answer). For more information, please follow other related articles on the PHP Chinese website!