Home > Web Front-end > JS Tutorial > javascript获取select值的方法分析

javascript获取select值的方法分析

WBOY
Release: 2016-06-01 09:54:31
Original
2151 people have browsed it

本文实例讲述了javascript获取select值的方法。分享给大家供大家参考。具体分析如下:

1. 获取选中值得文本

<code class="language-javascript">document.getElementById("bigclass").options[window.document.getElementById("bigclass").selectedIndex].text</code>
Copy after login
Copy after login

2. 获取数据库中的id

<code class="language-javascript">window.document.getElementById("bigclass").value</code>
Copy after login
Copy after login

3.获取select组分配的索引id

<code class="language-javascript">window.document.getElementById("bigclass").selectedIndex</code>
Copy after login
Copy after login

例子

<code class="language-javascript"><select name="bigclass" id="bigclass" onchange="javascript:updatePage2();">
<option value="" selected>ajax实验</option>
<option value="4">我适宜市哈</option>
</select></code>
Copy after login

 

使用:

<code class="language-javascript">document.getElementById("bigclass").options[window.document.getElementById("bigclass").selectedIndex].text</code>
Copy after login
Copy after login

结果是:我适宜市哈

 

使用:

<code class="language-javascript">window.document.getElementById("bigclass").value</code>
Copy after login
Copy after login

结果是:4

 

使用:

<code class="language-javascript">window.document.getElementById("bigclass").selectedIndex</code>
Copy after login
Copy after login

结果是:1

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