2

我在 IE8 中遇到 jQuery 问题(Firefox、Chrome 和 IE 9 都很完美)。我在 IE 9 以下时使用 jQuery 1.7.1 和 JS html5shiv

这段代码的问题是一个复选框。在 IE 8 中什么都不做,没有标记或取消选中选项。

    <div class="easy-select-box checklist category">
                    <a href="#">All Categories</a>
                    <ul>
                                <li><label><input type="checkbox" onchange="filter();" id="all" value="00"/> All Categories</label></li>
                                <li><label><input type="checkbox" name="cat[]" value="1" id="1" onchange="filter();"/> 1 category</label></li>
                                <li><label><input type="checkbox" name="cat[]" value="2" id="2" onchange="filter();"/> 2 Category</label></li>
                                <li><label><input type="checkbox" name="cat[]" value="3" id="3" onchange="filter();"/> 3 Category</label></li>
                                <li><label><input type="checkbox" name="cat[]" value="4" id="4" onchange="filter();"/> 4 Category</label></li>
                    </ul>
                </div>

jQuery('.checklist li label').click(function(){

if(jQuery(this).parent().is(':first-child')){

        if(jQuery(this).children('input').is(':checked')){

            jQuery('.checklist li').addClass('check');
            jQuery('.checklist > a').text(jQuery(this).text());
            jQuery('.checklist input').attr('checked', true);
        } else {
            jQuery('.checklist > a').text("Select Categories");
            jQuery('.checklist li').removeClass('check');
            //jQuery('.checklist input').attr('checked', false);
            jQuery('.checklist input').removeAttr('checked');
        }

    }else{      

        if(jQuery(this).children('input').is(':checked')){

            jQuery(this).parent().addClass('check');
        } else {
            jQuery('.checklist > a').append("a");
            jQuery(this).parent().removeClass('check');
            jQuery('.checklist li:first-child').removeClass('check');
            //jQuery('.checklist li:first-child input').attr('checked', false);
            jQuery('.checklist li:first-child input').removeAttr('checked');
        }   
    }
});
4

0 回答 0