• [ jquery 过滤器 parents(expr) ] 此方法用于在选择器的基础之上搜索被选元素沿着父元素链找到符合参数的那个父元素,完成需求,如果没有参数,他会一直沿着父元素链解析到 html 标签


    取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素 "!DOCTYPE html")。可以通过一个可选的表达式进行筛选

    实例:

    <html lang='zh-cn'>
    <head>
    <title>Insert you title</title>
    <meta http-equiv='description' content='this is my page'>
    <meta http-equiv='keywords' content='keyword1,keyword2,keyword3'>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type='text/javascript' src='./js/jquery-1.12.1.min.js'></script>
    <style type="text/css">
        *{margin:0;padding:0;}
        html{font:400 15px/1.2em 'Courier New';color:#666;750px;margin:25px auto;}
        div > p{white-space: pre-wrap;margin:15px 0;}
        div >*{text-indent:8px;}
        .hover{color:#FF96EC;}
    </style>
    <script type='text/javascript'>
        $(function(){
        //可以使用传递参数来限制范围
            //$('img.pic').parents().addClass('hover'); // 他会一直沿着父元素链解析到 html 标签 
             $('img.pic').parent('.sup').addClass('hover');  // 沿着父元素链找到符合参数的那个父元素,添加类名hover
        });
    </script>
    </head>
    <body>
        <div id='demo'>
            <div class='noClassDemo'>
                <ul class='list'>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#' class='pic'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                </ul>
                <ul class='list'>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                    <li><a href='#' class='sup'><img src='#' class='pic'></a></li>
                    <li><a href='#'><img src='#'></a></li>
                </ul>
            </div>
        </div>
    </body>
    </html>
  • 相关阅读:
    C语言函数名与函数指针详解
    在C语言中以编程的方式获取函数名
    Python 数据分析:Pandas 缺省值的判断
    手摸手教你如何在 Python 编码中做到小细节大优化
    如何在 Swoole 中优雅的实现 MySQL 连接池
    Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析
    Python 如何连接并操作 Aws 上 PB 级云数据仓库 Redshift
    Swoole 协程 MySQL 客户端与异步回调 MySQL 客户端的对比
    Protobuf 文件生成工具 Prototool 命令详解
    PHP 查看扩展信息的命令
  • 原文地址:https://www.cnblogs.com/mysearchblog/p/5617345.html
Copyright © 2020-2023  润新知