如何在JavaScript / Rails中创建多个tr函数?

问题描述 投票:0回答:1

我正在使用Rails,也正在使用JavaScript。我在获取表中多个tr的Javascript函数时遇到麻烦。我正在使用引导程序来显示我的模态,并且对于第一个tr来说一切正常,但对其他代码则无效:

  <script type = "text/javascript">
  $(function(){
    $("#btn-show-modal").click(function(e){

      $("#dialogue-example").modal('show');

    });
    $("#btn-close-modal").click(function(c){
      $("#dialogue-example").modal('hide');

    });
  });
  </script>



<table class="table table-striped">
  <thead>
    <tr>
      <th>Brand</th>
      <th>description</th>
      <th>Rate</th>
      <th>Date</th>
    </tr>
  </thead>
  <tbody>
    <% @products.each do |product| %>
      <tr id ="btn-show-modal">

        <td><%= product.brand %></td>
        <td><%= product.short_description %></td>
        <td><%= product.rate_amount %></td>
        <td><%= product.created_at %></td>
          <% name = product.name %>
          <% description = product.description %>
      </tr>



  </tbody>
  <% end %>
</table>
javascript ruby-on-rails ruby-on-rails-4 jquery-events
1个回答
0
投票

@BenjaminGruenbaum wrote in a comment

ID是唯一的(只能在一个元素上使用,请改为使用类。

© www.soinside.com 2019 - 2024. All rights reserved.