![](/img/trans.png)
[英]How to use jQuery to assign a class to only one radio button in a group when user clicks on it?
[英]using jquery how to change a model when the user clicks a radio button
我有一個包含這樣的行的表單。 當用戶單擊單選按鈕時,我需要能夠使用ajax / jquery在控制器上調用方法。 該方法將更改基礎模型,返回時將在客戶端的Flash中顯示一條消息。
<tr>
<td><%= radio_button_tag 'primary', feature_photo.id %></td>
<td>
<%= feature_photo.name %>
By: <%= feature_photo.photo_credit %>
</td>
<tr>
您正在尋找observed_field 。 其余的操作與任何其他rails操作(控制器中返回文本,javascript等相關內容的操作)一樣簡單。
您還提到了jQuery,但是在應用程序中如何使用它並不明顯。 observe_field
將生成原型代碼,而不是jQuery。 如果您有一些jQuery,則可以為單選按鈕編寫一個處理程序,也許像這樣:
$('#primary').bind( 'change', function() {
$.ajax( {
url: 'some_rails_action',
data: $(this).is(':checked'),
success: function( r ) {
// do something with the response from rails here
}
} );
} );
有了更多詳細信息,我也許可以提供更全面的幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.