Home > Web Front-end > JS Tutorial > How to get the selected value and text of drop-down list in jquery?

How to get the selected value and text of drop-down list in jquery?

云罗郡主
Release: 2018-10-27 13:36:52
forward
3402 people have browsed it

The content of this article is about how jquery obtains the selected value and text of a drop-down list. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Page drop-down list

Select the time period:

<select name="timespan" id="timespan" class="Wdate"   >
                           <option value="1">8:00-8:30</option>
                           <option value="2">8:30-9:00</option>
                           <option value="3">9:00-9:30</option>
</select>
Copy after login

After the last value is selected, the corresponding value and text value need to be obtained. As shown in the picture:

How to get the selected value and text of drop-down list in jquery?

jquery code to get the selected value and text of the drop-down list:

var obj = $("#timespan option:selected");
var  artime_val  = obj.val();
var  artime_text  = obj.text();
alert("val:"+artime_val+" text"+ artime_text );//val:3 text 9:00-9:30
Copy after login
The above is a complete introduction to how jquery gets the selected value and text of the drop-down list. If If you want to know more about jQuery, please pay attention to the PHP Chinese website.


The above is the detailed content of How to get the selected value and text of drop-down list in jquery?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:lvyestudy.com
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