javascript - 如何使用 ruby​​ on rails 中的复选框来选择行?

标签 javascript ruby-on-rails ruby ruby-on-rails-3

这是单位表:

<div id="table_header">Units</div>
<table class="gridView location">
  <tr class="gridViewHeader">
  <th><%= check_box("select", "all", {class: 'location'}) %></th>
  <th>Location Code</th>
  <th>Location Reference</th>
  <th>Address</th>
  </tr>

  <tr class="<%= cycle('gridViewclickableRowDialog', 'gridViewAltclickableRowDialog') %> current_location">
    <td><%= check_box("select", "all", {class: 'current_location'}) %></td>
    <td><%= current_location_id %></td>
    <td><%= current_location.Lo_Reference %></td>
    <td><%= current_location %></td>
  </tr>
</table>

这是选定单位表:

<div id="table_header">Selected Units</div>
<table class="gridView location">
  <tr class="gridViewHeader">
  <th><%= check_box("select", "all", {class: 'location'}) %></th>
  <th>Location Code</th>
  <th>Location Reference</th>
  <th>Address</th>
  </tr>

  <tr class="<%= cycle('gridViewclickableRowDialog', 'gridViewAltclickableRowDialog') %> current_location">
    <td><%= check_box("select", "all", {class: 'current_location'}) %></td>
    <td><%= current_location_id %></td>
    <td><%= current_location.Lo_Reference %></td>
    <td><%= current_location %></td>
  </tr>
</table>

要推送的图像按钮

<%= image_tag("blue_right_arrow.png", id: 'blue_right_arrow', :alt => "arro", title: 'Move to Selected Units') %>

通过单击此按钮Units 表中的选定行应传输到Selected Units 表。

提前致谢!

最佳答案

修改后的标记

<div class="table_header">Units</div>
<table class="gridView location" id="units">
  <thead>
    <tr class="gridViewHeader">
      <th><%= check_box("select", "all", {:class => "location"}) %></th>
      <th>Location Code</th>
      <th>Location Reference</th>
      <th>Address</th>
    </tr>
  </thead>

  <tbody>
    <tr class="current_location">
      <td><%= check_box("select", "all", {:class => "current_location"}) %></td>
      <td><%= current_location_id %></td>
      <td><%= current_location.Lo_Reference %></td>
      <td><%= current_location %></td>
    </tr>
  </tbody>
</table>


<div class="table_header">Selected Units</div>
<table class="gridView" id="selected_units">
  <thead>
    <tr class="gridViewHeader">
      <th><%= check_box("select", "all") %></th>
      <th>Location Code</th>
      <th>Location Reference</th>
      <th>Address</th>
    </tr>
  </thead>

  <tbody> 
    <tr class="<%= cycle('gridViewclickableRowDialog', 'gridViewAltclickableRowDialog') %>">
      <td><%= check_box("select", "all") %></td>
      <td><%= current_location_id %></td>
      <td><%= current_location.Lo_Reference %></td>
      <td><%= current_location %></td>
    </tr>
  </tbody>
</table>

<%= image_tag("blue_right_arrow.png", id: 'blue_right_arrow', :alt => "arro", title: 'Move to Selected Units') %>

记下添加的新类。

Jquery代码

$(document).ready(function() {
  #copying the tr
  $("#blue_right_arrow").click(function() {
    $("input.current_location").each(function(i, el) {
      if($(el).is(":checked")) {
        $("table#selected_units tbody").append($(el).parent().parent().html());
        $(el).remove()
      }
    });
  });
}); 

关于javascript - 如何使用 ruby​​ on rails 中的复选框来选择行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12911482/

相关文章:

javascript - 在 Javascript 中旋转图像时奇怪的定位问题

ruby-on-rails - 生成唯一的文件名

javascript - Rails 3 将变量从 link_to 传递到 javascript

ruby - ruby/rails 中的 openssl smime

ruby-on-rails - 无法要求将 gem 加载为 add_development_dependency

ruby - 迭代器的无限产量

javascript - 将 cookie 添加到 js fiddle 以保存用户键入的内容

javascript - 为什么lodash有gt、lt、gte、lte功能?

mysql - 按一年中的周查找 ActiveRecord 对象

javascript - 为什么 navigator.appCodeName 返回 Mozilla?