zoukankan      html  css  js  c++  java
  • jquery属性方法hasClass判断是否存在某个class

    判断匹配集合中是否存在至少一个元素使用样式'selected',存在则返回'true',不存在为'flase'。

    <html>  
    <head>  
    <script src="http://code.jquery.com/jquery-latest.js"></script>  
    <script>  
    $(document).ready(function(){  
    $("div#result1").append($("p:first").hasClass("selected").toString());  
    $("div#result2").append($("p:last").hasClass("selected").toString());  
    $("div#result3").append($("p").hasClass("selected").toString());  
    });  
    </script>  
    <style>  
    p{ margin: 8px; font-size:16px; }  
    .selected{ color:red; }  
    .highlight{ background:yellow; }  
    </style>  
    </head>  
    <body>  
    <p>Hello</p>  
    <p class="selected">Goodbye</p>  
    <div id="result1">First paragraph has selected class: </div>  
    <div id="result2">Last paragraph has selected class: </div>  
    <div id="result3">Some paragraph has selected class: </div>  
    </body>  
    </html>

    $("div#result1").append($("p:first").hasClass("selected").toString());
    $("div#result2").append($("p:last").hasClass("selected").toString());
    $("div#result3").append($("p").hasClass("selected").toString());
    第一行判断p集合中第一个p元素是否使用'selected'样式。
    第二行判断p集合中最后一个p元素是否使用'selected'样式。
    第一行判断p集合中每一个p元素是否至少有一个使用'selected'样式。

  • 相关阅读:
    kernel 单独编译模块
    Python实现图的经典DFS、BFS、Dijkstra、Floyd、Prim、Kruskal算法
    Python实现BFS和DFS
    dpdk 20.02 igb_uio.ko 编译
    Kubernetes 文档
    controller-runtime/FAQ.md
    kubebuilder2.0学习笔记——进阶使用
    cloud-init 导致虚拟机启动太慢
    关闭 cloud-init 服务
    centos7 安装 docker calico
  • 原文地址:https://www.cnblogs.com/afish/p/4186335.html
Copyright © 2011-2022 走看看