0

HTML

<div>Group 1
    <br>

        <input type="checkbox" name="testing" value="B"> <label>A<span>(34)</span></label>
    <br />
        <input type="checkbox" name="testing" value="I"> <label>B<span>(0)</span></label>
    <br />
        <input type="checkbox" name="testing" value="A"> <label>C<span>(323)</span></label>
    <br />
</div>
<div>Group 2
    <br>

        <input type="checkbox" name="testing2" value="B"><label>A<span>(0)</span></label>
    <br />

        <input type="checkbox" name="testing2" value="I"><label>B<span>(564)</span></label>
    <br />

        <input type="checkbox" name="testing2" value="A"> <label>C<span>(0)</span></label>
    <br />
</div>

JS

$("input:checkbox").change(function () {
    var checkname = $(this).attr("name");

    if (this.checked) {

        $("input:checkbox[name='" + checkname + "']").removeAttr("checked").parent().hide();
        this.checked = true;
        $(this).parent().show();
    } else {
        $("input:checkbox[name='" + checkname + "']").parent().show();
    }

    if($(".options input:checkbox + label span:contains('(0)')")){
        $(this).parent().hide();;
    }else{
        $(this).parent().show();
    }
});


$("input:checkbox[checked]").trigger("change"); 

如果子跨度包含(0),我想隐藏带有标签的复选框。你可以看到我在上面尝试过的,但它不起作用。怎么做 ?

http://jsfiddle.net/warface/uvYzW/4/

4

2 回答 2

1

标记:

<div>Group 1
    <div>
        <input type="checkbox" name="testing" value="B"> <label>A<span>(34)</span></label>
    </div>
    <div>
        <input type="checkbox" name="testing" value="I"> <label>B<span>(0)</span></label>
    </div>
</div>

JS:

$("label span:contains('(0)')").closest("div").hide();
于 2013-04-04T19:35:14.060 回答
0

试试这个:

$.each( $("input[type=checkbox]") , function(key, value) {  
    var element = $(value);
    if (element.next().find("span").text()==="(0)") {               
        element.prev().hide();  // remove the <br>
        element.hide();
        element.next().hide(); // remove the label
    }   
});

http://jsfiddle.net/Hgg58/2/

于 2013-04-04T19:57:58.683 回答