Home  >  Article  >  Web Front-end  >  Javascript operates dom object select (detailed answer)

Javascript operates dom object select (detailed answer)

亚连
亚连Original
2018-05-19 10:58:021823browse

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!

Statement:
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