zoukankan      html  css  js  c++  java
  • 利用jQuery中的filter来过滤重复结构的xml数据

     1 <?xml version="1.0" encoding="utf-8" ?>
     2 <bookstore>
     3     <book>
     4         <title>Rain</title>
     5         <year>2010</year>
     6         <author>Martin</author>
     7     </book>
     8     <book>
     9         <title>Cloud</title>
    10         <year>2009</year>
    11         <author>Robert</author>
    12     </book>
    13     <book>
    14         <title>River</title>
    15         <year>2007</year>
    16         <author>Fred</author>
    17     </book>
    18 </bookstore>

    引入jQuery如下:

    <script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
    <script type="text/javascript" src="Scripts/test.js"></script>

    test.js的代码如下:

    $(document).ready(function () {
        $.get("xmlData/Categories.xml", function (xml) {
                       $(xml).find("book").filter(
                        function (index) {
                            return "Rain" == $(this).find("title").text();
                        }
                       ).each(
                        function (index) {
                            alert($(this).find("author").text());
                                });
        });
    });

    输出结果:Martin

  • 相关阅读:
    模块
    Queue(队列)
    Stack(栈)
    Vector(容器)
    位图像素的颜色
    大数处理之三(除法)
    大数处理之二(幂运算)
    浮点数(double)的优势
    大数处理之一(加法和乘法)
    Depth-First Search
  • 原文地址:https://www.cnblogs.com/mingle/p/jQuery_Filter.html
Copyright © 2011-2022 走看看