質問

I have multiple checkboxes that I read and combine to a comma-separated string. With that string I want to hide everything in a table not containing this comma-separated string. The different checkboxes return different values (72.0 x 102.0, 64.0 x 90.0, 90.0 x 64.0) My code:

$('#kbafilter input[type="checkbox"]').click(function(){
       contain=$('#kbafilter :checked').map(function() {return ':contains("' + this.value + '")';}).get().join(',');
       alert(contain);
       if($(this).is(':checked')){
            $('#orderlist tbody tr:not(' + contain +')').hide();
        }
        else{
            $('#orderlist tbody tr:not(:contains(' + $(this).val() + '))').show();
        }
    });

This code doesnt work, it will only show what matches the first checkbox checked, but if I change the IF that is TRUE to

    $('#orderlist tbody tr:not(:contains("72.0 x 102.0"),:contains("64.0 x 90.0"))').hide();    //working

Then my table will hold only those TR that contains either "72.0 x 102.0" or "64.0 x 90.0"

So what could be wrong. The contain-line that works is copied directly from what the alert() pops out!?!?

Best regards Niclas

役に立ちましたか?

解決

Give this a try

JSFiddle

$(function () {
    $('#kbafilter input[type="checkbox"]').click(function () {
        $('#orderlist tbody tr').show();
        if ($('#kbafilter :checked').length > 0) {
            contain = $('#kbafilter :checked').map(function () {
                return ':contains("' + this.value + '")';
            }).get().join(',');
            $('#orderlist tbody tr:not(' + contain + ')').hide();
        }
    });
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top