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

  • 相关阅读:
    LR(0)分析法
    算符优先法之优先表构造
    自上而下的LL(1)语法分析法
    K倍区间
    全排列
    mysql自动获取时间日期
    限制
    JQuery
    LinQ 组合查询与分页
    LinQ 简单使用
  • 原文地址:https://www.cnblogs.com/mingle/p/jQuery_Filter.html
Copyright © 2011-2022 走看看