0

与以下功能结合使用时,这些复选框将停止接受任何输入。我在这里发布了一个演示问题的小提琴:http: //jsfiddle.net/chayacooper/WZpMh/32/

HTML

<ul id="attributes-Colors">
    <li><input type=checkbox name="color[]" value="Blue" data-color="Blue">Blue</li>
    <li><input type=checkbox name="color[]" value="Red" data-color="Red">Red</li>
    <li><input type=checkbox name="color[]" value="Black" data-color="Black">Black</li>
</ul> 

JS

 $(document).ready(function () {
    var selected = [];
    $('#attributes-Colors *').click(function () {
        var attrColor = $(this).data('color');
        var $this = $(this);
        if ($this.parent().hasClass("active")) {
            $this.parent().removeClass("active");
            selected.splice(selected.indexOf(attrColor),1);
        }
        else {
            $this.parent().addClass("active");
            selected.push(attrColor);
        }
        $("#content").find("*").hide();
        $.each(selected, function(index,item) {
            $('#content').find('[data-color ~="' + item + '"]').show();
        });
        return false;
    });
});   
4

1 回答 1

2

如果您return false在单击处理程序中删除 ,复选框将响应。

于 2013-03-25T22:00:33.810 回答