zoukankan      html  css  js  c++  java
  • jQuery 的filter(),not(),split()用法

    filter()和not():
    <script type="text/javascript">
    $(document).ready(function() {
    //输出   hello
    alert($("p").filter(".selected").html());
    //输出   How are you?
    alert($("p").not(".selected").html());
    });
    </script>

    </head>
    <body>

    <p class="selected">Hello</p><p>How are you?</p>
    <!--
    一个新的挑战是从一组类似或相同的元素中只选择某一个特定的元素。
    jQuery提供了filter()和not()来做这个。
    filter()能够将元素精简到只剩下满足过滤条件的那些,not()恰恰相反,他移除了所有满足条件的。-->
    </body>
     
    split():
    <script type="text/javascript">
    $(document).ready(function(){
    $("input[@value=btn1]").click(function(){
    //以¥分割
      alert($("span.sale").text().split("¥")[2]+"||"+$("span.sale").text().split("¥")[1]+"||"+$("span.sale").text().split("¥")[0]);
    });

    });
    </script>
    </head>

    <body>
    获取价格120:<input type="button" value="btn1" ><br>

    <span class="sale">
    Out Sale: ¥160<br />
    Deal Price: ¥120</span>


    <!--
    应用split来解决这个问题。下面给出一个用split的实例:
    msg ="2007/10/01";
         msg = msg.split("/");
         alert(msg[2]);
         他会把 msg 分成一个3块组成一个数组 ,然后就可以轻松获取了。
         -->
    </body>

  • 相关阅读:
    Python的传递引用
    kafka的ACK
    分布式事务
    Java中的锁
    docker笔记
    MySQL数据库优化
    Centos7使用yum命令安装Mysql5.6.X
    ubuntu16.04安装workbench
    ubuntu下IDEA配置tomcat报错Warning the selected directory is not a valid tomcat home
    ubuntu配置JDK
  • 原文地址:https://www.cnblogs.com/lixyvip/p/1559041.html
Copyright © 2011-2022 走看看