admin管理员组文章数量:1023025
if I'm passing a jquery object that I know is a select object, how can I get the text (not the value) of the option that is selected?
I'm needing something like this.
...function ($select){
var selectedText = $select.selected().text();
}
And since $select is already a jquery object, I cant really change the selector of the object to use ":selected".
if I'm passing a jquery object that I know is a select object, how can I get the text (not the value) of the option that is selected?
I'm needing something like this.
...function ($select){
var selectedText = $select.selected().text();
}
And since $select is already a jquery object, I cant really change the selector of the object to use ":selected".
Share Improve this question asked Jul 22, 2013 at 18:35 itcropperitcropper 7721 gold badge7 silver badges24 bronze badges 2-
I believe
.text()
should work. Post your code on JSFIDDLE, please. – user1477388 Commented Jul 22, 2013 at 18:36 - You can query within the object to find children elements. – scrappedcola Commented Jul 22, 2013 at 18:44
2 Answers
Reset to default 4$select.find(':selected').text();
should do.
You can use this:-
Suppose you have a dropdown like this:-
<select id="dropdown">
<option value="aa">a</option>
<option value="bb">b</option>
<option value="cc">c</option>
</select>
then javascript will be like this:-
$(document).ready(function() {
obj = $('#dropdown :selected')
value = obj.val()
alert(value) # will alert aa/bb/cc
text = obj.text()
alert(text) # will alert a/b/c
})
if I'm passing a jquery object that I know is a select object, how can I get the text (not the value) of the option that is selected?
I'm needing something like this.
...function ($select){
var selectedText = $select.selected().text();
}
And since $select is already a jquery object, I cant really change the selector of the object to use ":selected".
if I'm passing a jquery object that I know is a select object, how can I get the text (not the value) of the option that is selected?
I'm needing something like this.
...function ($select){
var selectedText = $select.selected().text();
}
And since $select is already a jquery object, I cant really change the selector of the object to use ":selected".
Share Improve this question asked Jul 22, 2013 at 18:35 itcropperitcropper 7721 gold badge7 silver badges24 bronze badges 2-
I believe
.text()
should work. Post your code on JSFIDDLE, please. – user1477388 Commented Jul 22, 2013 at 18:36 - You can query within the object to find children elements. – scrappedcola Commented Jul 22, 2013 at 18:44
2 Answers
Reset to default 4$select.find(':selected').text();
should do.
You can use this:-
Suppose you have a dropdown like this:-
<select id="dropdown">
<option value="aa">a</option>
<option value="bb">b</option>
<option value="cc">c</option>
</select>
then javascript will be like this:-
$(document).ready(function() {
obj = $('#dropdown :selected')
value = obj.val()
alert(value) # will alert aa/bb/cc
text = obj.text()
alert(text) # will alert a/b/c
})
本文标签: javascriptHow to get the text value of the selected option of a select jquery objectStack Overflow
版权声明:本文标题:javascript - How to get the text value of the selected option of a select jquery object? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745593136a2158005.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论