最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get name of the dropdown selected item in jquery? - Stack Overflow

programmeradmin5浏览0评论

If i have the bookd_ids and book_titles as follows in the database:

 id   |  title
 ---------------
 1    |  abc
 2    |  xyz
 3    |  pqr

I have the books dropdownlist as show below:

<%=  select("books", "book_id", Book.all.collect {|b|
                [ b.title, b.id ] }, {:include_blank => 'Select Book'})%>

i can get the id of the books thru query this way:

var id = $("#books_book_id").val();

How to get the abc, xyz pqr titles using jquery?

If i have the bookd_ids and book_titles as follows in the database:

 id   |  title
 ---------------
 1    |  abc
 2    |  xyz
 3    |  pqr

I have the books dropdownlist as show below:

<%=  select("books", "book_id", Book.all.collect {|b|
                [ b.title, b.id ] }, {:include_blank => 'Select Book'})%>

i can get the id of the books thru query this way:

var id = $("#books_book_id").val();

How to get the abc, xyz pqr titles using jquery?

Share Improve this question edited Jul 21, 2011 at 16:57 Naftali 146k41 gold badges247 silver badges304 bronze badges asked Jul 21, 2011 at 16:55 KumarKumar 7412 gold badges12 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13
var text = $("#books_book_id option:selected").text();

Have put some space between :selected

var value = jQuery("#edit-system-name :selected").text();
发布评论

评论列表(0)

  1. 暂无评论