如何更改颜色按钮无需重新加载页面

How to change color button no reloading the page

本文关键字:加载 新加载 颜色 何更改 按钮      更新时间:2023-10-09

我有一组按钮:

<div class="panel-body">
    <% @tables.each do |table| %>
        <%= button_to table.seats, service_path, method: :get, class: ["btn", "btn-primary", "btn-lg"], remote: true %>
    <% end %>
</div>

我想点击一个按钮,在不重新加载页面的情况下更改它的颜色。这个想法是有一组蓝色按钮,当点击其中一个按钮时,它的颜色会变为红色

此外,将session[:table]设置为table的id,而无需重新加载页面。

--已添加--

注意:我一次只想要一个红色按钮。

$(".btn").click(function(){
$(this).css({"background-color":"#00f"});
});