Home > Web Front-end > JS Tutorial > JS method to get select-option-text_value_javascript skills

JS method to get select-option-text_value_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:06:55
Original
1225 people have browsed it

HTML代码:

复制代码 代码如下:


用jQuery获取 select选中对象的value、text

复制代码 代码如下:

$(function(){
    $("#month").change(function() {
        alert($(this).find("option:selected").val());
        alert($(this).find("option:selected").text());
    });
});

如果用JS获取 select选中对象的value是很容易的

复制代码 代码如下:

function selectInput(oSelect) {
    alert(oSelect.value);
}

如果要用JS获取 select选中对象的text呢 ?

复制代码 代码如下:

function selectInput(oSelect) {
    alert(oSelect.options[oSelect.selectedIndex].text);
}

如果select 没有默认则设第一个为默认?

复制代码 代码如下:

document.getElementById("test“).options[0].selected=true;
Related labels:
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
Latest Issues
AngularJS Select default value?
From 1970-01-01 08:00:00
0
0
0
Select option using PHP loop
From 1970-01-01 08:00:00
0
0
0
Chrome doesn't apply padding to select options
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template