• jQuery 基础教程(第3版) ---第九章习题答案


    //第一题
    $(document).ready(function(){
        function stripe(){
            $('#news').find('tr.alt').removeClass('alt');
            $('#news tbody').each(function(){
                $(this).children(':visible').has('td').filter(
                    function(index){
                        return (index%3)==1;
                    }
                ).addClass('alt').end().filter(
                    function(index){
                        return (index%3)==2;
                    }
                ).addClass('alt-2');
            });
        }
        
        stripe();
        
        
        $('#topics a').click(function(){
            var topic = $(this).text();
            
            $('#topics a.selected').removeClass('selected');
            $(this).addClass('selected');
            
            $('#news').find('tr').show();
            if(topic!='All'){
                $('#news').find('tr:has(td)').not(function(){
                    return $(this).children(':nth-child(4)')
                            .text()==topic;
                
                }).hide();
            }
            
            stripe();
            return false;
            
        });
    });
    
    //第二题
    (function($){
        $.extend($.expr[':'],{
            containsExactly:function(element,index,matches,set){
                var value = matches[3];
                var x = $(element).text();
                if(value!=x){
                    return false
                }
                return true;
            }
        });
    })(jQuery);
    //可使用的调用方法
    $('#news td').click(function(){
        $(this).filter(':containsExactly("XXX")').addClass('YYY');
    });
    
    
    //第三题
    if(topic!='All'){
        //原代码
        $('#news').find('tr:has(td)').not(function(){
            return $(this).children(':nth-child(4)').text()==topic;
        }).hide();
        
        //新的
        $('#news').find('tr:has(td)').not(':containsExactly('+topic+')').hide();
        
    } 
    //第四题
    (function($){
        $.fn.grandparent=function(){
            var $current=$();
            this.each(function(){
                $current = $(this).parents();
            });
            return this.pushStack($current);
        }
    })(jQuery);
  • 相关阅读:
    建造者模式
    js日期转化(计算一周的日期)
    vue实现全选效果
    less入门
    使用node初始化项目
    ES5新语法forEach和map及封装原理
    es6中的promise对象
    深入理解jsonp跨域请求原理
    markdown语法与使用
    Ajax商品分类三级联动实现
  • 原文地址:https://www.cnblogs.com/wanlxz/p/3477998.html
Copyright © 2020-2023  润新知