Javascript 如何在选中/取消选中该行的复选框时添加或删除表单元格中的值,并尝试通过Jquery提交该值?

Javascript 如何在选中/取消选中该行的复选框时添加或删除表单元格中的值,并尝试通过Jquery提交该值?,javascript,ruby-on-rails-3,jquery,Javascript,Ruby On Rails 3,Jquery,这是表格: <%= form_tag '', :id => "costs" do %> <table class="table table-bordered" id="service_cost"> <% @services.each do |service| %> <tbody> <tr> <td><%= check_box_tag :open_servi

这是表格:

<%= form_tag '', :id => "costs" do %>
<table class="table table-bordered" id="service_cost">
    <% @services.each do |service|  %>
    <tbody>
        <tr>
            <td><%= check_box_tag :open_service,  {}, false, :class => 'checkable' %></td>  
            <td><%= service.phone %></td>
            <td><%= service.internet %></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td><%= service.house_keeping  %> </td>
            <td>0.0 </td>
            <td><%= service.laundry %></td>
            <td><%= text_field_tag "service_cost", service.total, :class => "input-small" %></td>
        </tr>
    </tbody>
    <% end %>
</table>
<% end %>
这可确保选中复选框时提交表单:

$('.checkable').live('change', function() {
  $(this).parents('form:first').submit();
});

但是,我要寻找的是根据复选框选择/取消选择添加或删除单元格值并提交,请建议一种方法。

如果表有多行,则不确定隐藏是否适用于td,但如果它这样做:

<table>
    <tr>
        <td class="data">data</td>
        <td><input type="checkbox" class="checkable" value="data"></td>
    </tr>
</table

$('.checkable').live('change', function() {
      $(this).closest('tr.data').hide();
      $(this).parents('form:first').submit();

});

数据

“成本”do%>
20 %>
$('#check')。在('change',function()上{
如果($('#check')。是(':checked'))
$('#detbycb').val('我被选中');
其他的
$('#detbycb').val('我没有被选中');
}
或
$('#check')。在('change',function()上{
如果($(this).is(':checked'))
$('#detbycb').val('我被选中');
其他的
$('#detbycb').val('我没有被选中');
}
第一个更好地说明了,第二个是真实的方式,更快的执行

RE:如何将var row添加到serializeArray()中-不确定这是如何工作的,我通常使用.serialize(),它将通过ajax为您提交所有表单数据。只需检查复选框的值,如果有复选框,则勾选它
<table>
    <tr>
        <td class="data">data</td>
        <td><input type="checkbox" class="checkable" value="data"></td>
    </tr>
</table

$('.checkable').live('change', function() {
      $(this).closest('tr.data').hide();
      $(this).parents('form:first').submit();

});
<%= check_box_tag :check %>
<%= form_tag '', :id => "costs" do %>
  <%= text_field_tag, :detbycb, :size=>20 %>
<% end %>

$('#check').on('change', function() {
   if ( $('#check').is(':checked') )
      $('#detbycb').val('I Am Checked');
   else
      $('#detbycb').val('I AM NOT checked');
}

OR

$('#check').on('change', function() {
   if ( $(this).is(':checked') )
      $('#detbycb').val('I Am Checked');
   else
      $('#detbycb').val('I AM NOT checked');
}

The first better illustrates,  the second is the real way, faster execution