zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    C++中的函数
    C++基本语句
    面向对象程序设计
    数据结构中的算法
    数据结构开篇
    条件编译
    文件包含
    简单的宏替换
    系统启动过程
    parted 命令学习
  • 原文地址:https://www.cnblogs.com/wanlxz/p/3477998.html
Copyright © 2011-2022 走看看