Home  >  Article  >  Web Front-end  >  Analysis of jquery's method of obtaining the selected value of select_jquery

Analysis of jquery's method of obtaining the selected value of select_jquery

WBOY
WBOYOriginal
2016-05-16 15:24:221248browse

The example in this article describes how jquery obtains the selected value of select. Share it with everyone for your reference, the details are as follows:

Misunderstanding:

I used to think that jquery gets the text value of the selected option in the select, which is written like this:

Copy code The code is as follows:
$("#s").text(); //Get all options Text value

It should actually look like this:

Copy code The code is as follows:
$("#s option:selected").text(); //Get the text value of the selected option

Get the selected value of option in select:
$("#s").val();
$("#s option:selected").val();

js gets the value selected by select:

var sel=document.getElementById("select1");
var index = sel.selectedIndex; // 选中索引
albumid= sel.options[index].value;//要的值

I hope this article will be helpful to everyone in jQuery programming.

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