如何在函数后使复选框长度为nil
How to make checkbox length nil after fucntion
我有几个复选框和一个按钮,用于将选中的内容发送到垃圾箱。我的功能是选择并将它们发送到垃圾工厂。但是我的按钮发送到垃圾,应该只出现当复选框被选中和消失时,他们移动到垃圾。但是我的按钮不会消失,因为我的复选框值在删除时没有重置为零。任何想法如何重置我的复选框长度后移动到垃圾文件。我的代码如下,
$('input[name=myfile_select_id]').change(function() {
console.log("Touched");
console.log($('input[name=myfile_select_id]:checked').length);
if ($('input[name=myfile_select_id]:checked').length > 1) {
// one or more checkboxes are checked
$("#trash-select").show();
} else {
// no checkboxes are checked
$("#trash-select").hide();
}
});
$("#trash-select").click(function() {
console.log("CLI");
var selectedFiles = $('input[name=myfile_select_id]:checked');
var checkValues = selectedFiles.map(function() {
return $(this).val();
}).get();
if (confirm("Are you sure, you want to move these files to trashcan?")) {
$.ajax({
url: '/myfiles/multiple_select',
type: 'post',
data: {
myfile_ids: checkValues
},
success: function(data) {}
}).done(function() {
selectedFiles.each(function(index) {
console.log("I'm done");
$(this).closest('tr').remove();
});
});
} else {
console.log("not passed");
}
});
我的xyz.html.erb文件
<div class="File--Select">
<%= check_box_tag "myfile_select_id", myfile.id , false, :id => "myfile-select-#{myfile_path(myfile).to_s.split('/')[2]}" , :class => "file-select" %>
</div>
<div class="pull-right">
<%= button_tag :id =>"trash-select", :class => "btn btn-sm btn-danger", :style => "display:none" do %>
<span class="" aria-hidden="true"></span> Move to Trash
<% end %>
</div>
任何帮助都是感激的。TIA。
使用这个。可能对你有帮助
function reset(selectedFiles){
if(selectedFiles.length < 1) { $("#trash-select").hide();} }//can you call this function in ajax done function once removed the checkedbox row.
您应该在删除复选框后以编程方式触发' change '事件。
//You don't need each
selectedFiles.closest('tr').remove();
//Trgger cgnage event
$('input[name=myfile_select_id]').change();
需要在。done上隐藏按钮,因为更改事件不会在tr移除时触发。
.done(function() {
selectedFiles.each(function(index) {
console.log("I'm done");
$(this).closest('tr').remove();
// hide button on done
$("#trash-select").hide();
});
相关文章:
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 正在验证8个真/假复选框或复选框中的2个
- 为复选框javascript指定两个值
- 如何在单击复选框后调用控制器方法
- 从复选框和Selects-KnockoutJS中获取值的总和
- 选中多个具有相同名称的复选框
- 使用Jquery选择或取消选择ListView中的所有复选框
- Jquery表单验证插件-如果选中复选框,如何在提交时执行某些操作
- 使用$.ajax发布多个复选框
- AngularJS单选筛选不适用于Name、Description和Field4复选框值
- 使用jquery选中/取消选中单个复选框
- Angular JS Filter-通过3个复选框进行筛选
- 如果选中了多个复选框,如何添加事件
- Javascript复选框函数:;缺少:在属性id之后"
- JavaScript-切换“;全部检查”;复选框true/false
- 如何从javascript/jquery中的复选框中获取布尔值
- 在Ajax中捕获复选框值
- 显示隐藏复选框
- 发送'nil'对于未选中的复选框-UJS,Rails 4
- 如何在函数后使复选框长度为nil