如何在带有条件检查的复选框上单击以删除所选行 [英] how to delete the selected row on click of checkbox with condition check

查看:83
本文介绍了如何在带有条件检查的复选框上单击以删除所选行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除行,检查条件是否为0,如果选择的输入字段值为0(有一个输入字段),则仅应删除行. 请让我知道问题出在哪里.即使输入字段为0,也会删除所选行.

I am trying to delete the row checking the the condition where if selected with input field value is 0 (there is one input field), then only row should be deleted. please let me know where is the problem. it is deleted both the selected row even if once input filed is 0.

var purchased = $(".purchased input");
/*remove selected item start*/
$('.removeselected').on('click', function(){        
    var checkedstatus = $(".checker input:checked");

    $('.checker').each(function() {
        if((checkedstatus) && (purchased.val() == 0)){
            console.log("Varified");
            checkedstatus.parents(".renderedItem").remove();
        }else{
            console.log("not varified");
        }
    });
});
/*remove selected item end*/

推荐答案

遍历每个选中的复选框,然后检查同一行中购买的输入值,如果元素为0,则删除该元素

Iterate over each checked checkbox, then check purchased input value within the same row and remove the element if it's 0

$('.removeselected').on('click', function(){     
    $('.checker .checkboxitem:checked').each(function () {
        if ($(this).closest('.row').find('.purchased input').val() == 0) {
            $(this).closest('.checker').remove();
        }
    });
});

这篇关于如何在带有条件检查的复选框上单击以删除所选行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆