0

我在 create.js.erb 中有以下代码(每当将商品添加到购物车时通过 ajax 调用)

$('#cart').show('blind', 1000);

$('#cart').html("<%= j render @cart %>")

$('#current_item').css({'background-color':'#88ff88'}).animate({'background-color':'#114411'}, 1000)

显示方法不起作用。动画方法工作得很好。该片段与书中的完全相同(Agile Web Development with Rails 4e)

以下是渲染调用的汽车部分,_cart.html.erb

<div class="cart_title">Your Cart <%= "is Empty.." if !cart.line_items.any? %></div>
<% unless cart.line_items.empty? %>
<table>
  <%= render cart.line_items %>
  <tr class="total_line">
    <td colspan="2">Total</td>
    <td class="total_cell"><%= number_to_currency(cart.total_price) %></td>
  </tr>
</table>
<br />
<%= button_to 'Empty Cart', cart, method: :delete, confirm: 'Are you sure?' %>
<p><%= link_to 'Back to Store', store_path %></p>
<% end %>

使用 jquery 代码,每次将新元素添加到购物车时,购物车都应该执行 show 的行为。但它没有。.html 和 .css 调用以及 animate 函数都可以正常工作。

4

0 回答 0