1
值
,如果我有bookd_ids和book_titles在数据库如下:如何获得多个选择IDS
id | title
---------------
1 | abc
2 | xyz
3 | pqr
的观点如下所示::
<table>
<tr>
<td>
<%= select("books", "book_id", Book.all.collect {|b|
[ b.title, b.id ] },{:include_blank => false})%>
</td>
<td>
<img src="/images/add_icon.png"
alt="Add Book" width="20px" height="20px" onclick="AddBook()" />
</td>
</tr>
<tr>
<td id="current">
<br />
Current Books<br />
<p id="none" style="font-style: italic; font-weight: lighter">
None Selected</p>
</td>
</tr>
<tr>
<td id="tdbook"></td>
<td id="tdbookimg"></td>
</tr>
</table>
当我点击add_icon.png图像,它会将选定的图书添加到选定的图书标题下。如果我多次这样做,它会在选定的书籍下添加多个选定的行。
的AddBook()函数写为:
function AddBook(){
count = count + 1;
$('#none').hide();
var id = $("#books_book_id").val();
$("#tdbook").append("<p id='row" + id + "'><label for='txt" + id + "'>" +$("#books_book_id option:selected").text() + "</label></p>");
$("#tdbookimg").append("<p id='rowimg" + id + "'></p>");
}
我能得到一本通的jQuery这样的ID:
VAR ID = $( “#books_book_id”)VAL( );
如何在添加多个项目时获取多个ID。这样我就可以获得控制器中的值。
感谢, 库马尔