Javascript operates dom object select (detailed answer)

亚连
Release: 2018-05-19 10:58:02
Original
1827 people have browsed it

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>
Copy after login

js native operation

1. Get the select object;

var university=document.getElementById("university");
Copy after login

2. Get the select object The index value of option;

var index=university.selectedIndex;
Copy after login

3. Get the value of option selected by select;

var val=university.options[index];
Copy after login

4. Get the index of the selected option;

var text=university.options[index].text;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template