简体   繁体   English

尝试使用所有复选框删除,并收到错误

[英]try to delete using checkbox all, and receive error

<label><input type="checkbox" id="select_all"/>Select All</label>
<td><input class="chk" type="checkbox"/>Option 1</td>
<td><input class="chk" type="checkbox"/>Option 2</td>
<td><input class="chk" type="checkbox"/>Option 3</td>
<td><input class="chk" type="checkbox"/>Option 4</td>
<td><input class="chk" type="checkbox"/>Option 5</td>


<script type='text/javascript'>
$("#select_all").change(function(){
     $(".chk").prop('checked', $(this).prop("checked"));
});
</script>

After I select all using checkbox's i use my 'trash' to delete js.coffee 在我使用复选框全部选中之后,我使用我的“垃圾箱”删除js.coffee

 switch $(@).val()
      when "trash"
        _test = []
        $('#read_messages_table :checkbox:checked').each ->
          _test.push($(@).closest('tr').data('id'))
        $.post('/file/trash', test: _test).success (data) ->
          location.reload()

controller 控制者

def trash
params[:test].each do |n|
_test = Test.find(n)
_test.box = 'trash'
_test.save!
end
end

If i use button, everything work fine, but I don't want to use a button, I want to use a input for select all 如果我使用按钮,则一切正常,但我不想使用按钮,我想使用输入来选择全部

So, select all checkbox's is working, but if I use select all from checkbox, don't work and give this undefined index I think he try to use the first index of checkbox, this one, 因此,选择所有复选框均有效,但是如果我使用从复选框中选择全部,则不起作用并提供此未定义的索引,我认为他尝试使用复选框的第一个索引,

is possible to correct this? 有可能纠正这个问题吗?

Use your "chk" class 使用您的“ chk”课程

So in your file delete js.coffee, when your write the each code, just add checkbox.chk:checked 因此,在文件中删除js.coffee,在编写每个代码时,只需添加checkbox.chk:checked

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM