My HTML is below. I need to get the selected value (Scheduled
) using the <select>
tag. How can this be done using jQuery?
我的HTML在下面。我需要使用
<select id="availability" style="display: none;">
<option value="Available">Available</option>
<option selected="selected" value="Scheduled">Scheduled</option>
<option value="Unavailable">Unavailable</option>
</select>
I did a jQuery("#availability")
to get the select tag, but I do not know how to get the selected options' value.
我做了一个jQuery(“#availability”)来获取select标签,但我不知道如何获得所选选项的价值。
6 个解决方案
#1
57
Try:
尝试:
jQuery("#availability option:selected").val();
Or to get the text of the option, use text()
:
或者要获取选项的文本,请使用text():
jQuery("#availability option:selected").text();
More Info:
更多信息:
- http://api.jquery.com/val/
- http://api.jquery.com/val/
- http://api.jquery.com/text/
- http://api.jquery.com/text/
#2
11
The above solutions didn't work for me. Here is what I finally came up with:
上述解决方案对我不起作用。这是我最终提出的:
$( "#ddl" ).find( "option:selected" ).text(); // Text
$( "#ddl" ).find( "option:selected" ).prop("value"); // Value
#3
8
$("#availability option:selected").text();
This will give you the text value of your dropdown list. You can also use .val() instead of .text() depending on what you're looking to get. Follow the link to the jQuery documentation and examples.
这将为您提供下拉列表的文本值。您也可以使用.val()而不是.text(),具体取决于您要获得的内容。点击jQuery文档和示例的链接。
#4
5
I have gone through all the answers provided above. This is the easiest way which I used to get the selected value from the drop down list
我已经完成了上面提供的所有答案。这是我用来从下拉列表中获取所选值的最简单方法
$('#searchType').val() // for the value
$('#searchType')。val()//为值
#5
3
$('#availability').find('option:selected').val() // For Value
$('#availability').find('option:selected').text() // For Text
or
$('#availability option:selected').val() // For Value
$('#availability option:selected').text() // For Text
#6
0
Hello guys i am using this technique to get the values from the selected dropdown list and it is working like charm.
大家好,我正在使用这种技术从选定的下拉列表中获取值,它就像魅力一样。
var methodvalue = $("#method option:selected").val();
#1
57
Try:
尝试:
jQuery("#availability option:selected").val();
Or to get the text of the option, use text()
:
或者要获取选项的文本,请使用text():
jQuery("#availability option:selected").text();
More Info:
更多信息:
- http://api.jquery.com/val/
- http://api.jquery.com/val/
- http://api.jquery.com/text/
- http://api.jquery.com/text/
#2
11
The above solutions didn't work for me. Here is what I finally came up with:
上述解决方案对我不起作用。这是我最终提出的:
$( "#ddl" ).find( "option:selected" ).text(); // Text
$( "#ddl" ).find( "option:selected" ).prop("value"); // Value
#3
8
$("#availability option:selected").text();
This will give you the text value of your dropdown list. You can also use .val() instead of .text() depending on what you're looking to get. Follow the link to the jQuery documentation and examples.
这将为您提供下拉列表的文本值。您也可以使用.val()而不是.text(),具体取决于您要获得的内容。点击jQuery文档和示例的链接。
#4
5
I have gone through all the answers provided above. This is the easiest way which I used to get the selected value from the drop down list
我已经完成了上面提供的所有答案。这是我用来从下拉列表中获取所选值的最简单方法
$('#searchType').val() // for the value
$('#searchType')。val()//为值
#5
3
$('#availability').find('option:selected').val() // For Value
$('#availability').find('option:selected').text() // For Text
or
$('#availability option:selected').val() // For Value
$('#availability option:selected').text() // For Text
#6
0
Hello guys i am using this technique to get the values from the selected dropdown list and it is working like charm.
大家好,我正在使用这种技术从选定的下拉列表中获取值,它就像魅力一样。
var methodvalue = $("#method option:selected").val();