zoukankan      html  css  js  c++  java
  • [ jquery 过滤器 parent(expr) ] 此方法用于在选择器的基础之上搜索被选元素中符合表达式的父元素

    此方法用于在选择器的基础之上搜索被选元素中符合表达式的父元素

    取得一个包含着所有匹配元素的唯一父元素的元素集合,你可以使用可选的表达式来筛选:

    实例:

    <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').parent('.sup').addClass('hover');  将为两个img.pic的父元素添加类名hover
          $('img.pic').parent('.sup').addClass('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>
  • 相关阅读:
    为服务部署 Jekins的使用
    spring cloud
    docker
    WebSocket
    idea
    maven
    SQL四种语言(DDL、 DML、 DCL、 TCL)
    十大经典排序
    AVL树的旋转图解和简单实现
    多个线程交替打印
  • 原文地址:https://www.cnblogs.com/mysearchblog/p/5617163.html
Copyright © 2011-2022 走看看