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

javascript获取select值的方法分析

WBOY
WBOYOriginal
2016-06-01 09:54:312072browse

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

1. 获取选中值得文本

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

2. 获取数据库中的id

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

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

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

例子

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

 

使用:

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

结果是:我适宜市哈

 

使用:

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

结果是:4

 

使用:

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

结果是:1

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