Home > Web Front-end > JS Tutorial > Analysis of the method of obtaining the select value in javascript_javascript skills

Analysis of the method of obtaining the select value in javascript_javascript skills

WBOY
Release: 2016-05-16 15:52:00
Original
1206 people have browsed it

The example in this article describes the method of obtaining the select value in javascript. Share it with everyone for your reference. The specific analysis is as follows:

1. Get the displayed Chinese characters

Copy code The code is as follows:
document.getElementById("bigclass").options[window.document.getElementById(" bigclass").selectedIndex].text

2. Get the id in the database

Copy code The code is as follows:
window.document.getElementById("bigclass").value

3. Get the index id assigned by the select group

Copy code The code is as follows:
window.document.getElementById("bigclass").selectedIndex

Example:

<select name="bigclass" id="bigclass" onChange="javascript:updatePage2();">
<option value="" selected="selected">ajax实验</option>
<option value="4">我适宜市哈</option>
</select>

Copy after login

Use:

Copy code The code is as follows:
document.getElementById("bigclass").options[window.document.getElementById(" bigclass").selectedIndex].text

The result is: I am suitable for the city

Use:

Copy code The code is as follows:
window.document.getElementById("bigclass").value

The result is: 4

Use:

Copy code The code is as follows:
window.document.getElementById("bigclass").selectedIndex

The result is: 1

I hope this article will be helpful to everyone’s JavaScript programming design.

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