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>
  • 相关阅读:
    Kaka's Matrix Travels
    Cable TV Network
    LightOJ 1137
    SPOJ AMR11E Distinct Primes 基础数论
    HDU 5533Dancing Stars on Me 基础几何
    POJ 1014 / HDU 1059 Dividing 多重背包+二进制分解
    vijos 1180 选课 树形DP
    vijos 1313 金明的预算方案 树形DP
    LightOJ 1062
    vijos 1464 积木游戏 DP
  • 原文地址:https://www.cnblogs.com/mysearchblog/p/5617163.html
Copyright © 2011-2022 走看看