Home  >  Article  >  Web Front-end  >  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?

云罗郡主
云罗郡主forward
2018-10-27 13:36:523358browse

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>

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
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!

Statement:
This article is reproduced at:lvyestudy.com. If there is any infringement, please contact admin@php.cn delete