本帖最后由 tomvision 于 2014-09-28 14:28:58 编辑

解决方案 »

  1.   

    <script>
            $(function(){
                $("tbody tr:odd").addClass("odd");
                $("tbody tr:even").addClass("even");
                var $inp = $("input[type='checkbox']");
                $("tr").has($inp).click(function(){
                    $(this)
                        .addClass("selected")
                        .siblings().removeClass("selected");

    if($(this).find("input:checked").length>0)
    {
    $(this).find("input").removeAttr("checked");
    }else{
    $(this).find("input").attr("checked","checked");
    }
                       
                })
                $("tr:has(':checked')").addClass("selected");
            })
        </script>试试!
      

  2.   

    判断的顺序反了。
    <script>
            $(function(){
                $("tbody tr:odd").addClass("odd");
                $("tbody tr:even").addClass("even");
                var $inp = $("input[type='checkbox']");
                $("tr").has($inp).click(function(){
                    $(this)
                        .addClass("selected")
                        .siblings().removeClass("selected");
                        if($("input[checked!='checked']")){
                            $(this).find("input").attr("checked",true);
                        }
                        if($inp.is(":checked")){
                            $("input[checked='checked']").attr("checked",false);
                        }
                })
                $("tr:has(':checked')").addClass("selected");
            })
        </script>
      

  3.   

    先清空所有所选中,在给当前的选中$(function(){
                $("tbody tr:odd").addClass("odd");
                $("tbody tr:even").addClass("even");
                var $inp = $("input[type='checkbox']");
                $("tr").has($inp).click(function(){
                    $(this)
                        .addClass("selected")
                        .siblings().removeClass("selected");

        if($inp.is(":checked")){
                            $("input[checked='checked']").attr("checked",false);
                        }

                        if($("input[checked!='checked']")){
                            $(this).find("input").attr("checked",true);
                        }
                        
                })
                $("tr:has(':checked')").addClass("selected");
            })