jQuery读取XML文件的方法示例

发布时间:2020-10-19 20:13:17 作者:走路到纽约
来源:脚本之家 阅读:94

本文实例讲述了jQuery读取XML文件的方法。分享给大家供大家参考,具体如下:

<?xml version="1.0" encoding="utf-8" ?>
 <taxrates>
 <taxrate id="1">
  <lower>0</lower>
  <upper>500</upper>
  <rate>5</rate>
  <buckle>0</buckle>
 </taxrate>
 <taxrate id="2">
  <lower>500</lower>
  <upper>2000</upper>
  <rate>10</rate>
  <buckle>25</buckle>
 </taxrate>
 <taxrate id="3">
  <lower>2000</lower>
  <upper>5000</upper>
  <rate>15</rate>
  <buckle>125</buckle>
 </taxrate>
 <taxrate id="4">
  <lower>5000</lower>
  <upper>20000</upper>
  <rate>20</rate>
  <buckle>375</buckle>
 </taxrate>
 <taxrate id="5">
  <lower>20000</lower>
  <upper>40000</upper>
  <rate>25</rate>
  <buckle>1375</buckle>
 </taxrate>
 <taxrate id="6">
  <lower>40000</lower>
  <upper>60000</upper>
  <rate>30</rate>
  <buckle>3375</buckle>
 </taxrate>
 <taxrate id="7">
  <lower>60000</lower>
  <upper>80000</upper>
  <rate>35</rate>
  <buckle>6375</buckle>
 </taxrate>
 <taxrate id="8">
  <lower>80000</lower>
  <upper>100000</upper>
  <rate>40</rate>
  <buckle>10375</buckle>
 </taxrate>
 <taxrate id="9">
  <lower>100000</lower>
  <upper>99999999</upper>
  <rate>45</rate>
  <buckle>15375</buckle>
 </taxrate>
</taxrates>
function StandardTaxRate()
{
  $.ajax({
    url: "/Resource/salaryTaxRate.xml",
    dataType: 'xml',
    type: 'GET',
    timeout: 2000,
    error: function(xml)
    {
      alert("加载XML 文件出错!");
    },
    success: function(xml)
    {
      $(xml).find("taxrate").each(function(i)
      {
        var oid = $(this).attr("id");
        var lower = $(this).children("lower").text();
        var upper = $(this).children("upper").text();
        var rate = $(this).children("rate").text();
        var buckle = $(this).children("buckle").text();
        ///后续操作。。。
      });
    }
  });
}

PS:这里再为大家提供几款关于xml操作相关在线工具供大家参考使用:

在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson

在线格式化XML/在线压缩XML
http://tools.jb51.net/code/xmlformat

XML在线压缩/格式化工具:
http://tools.jb51.net/code/xml_format_compress

xml代码在线格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery操作xml技巧总结》、《jQuery操作json数据技巧汇总》、《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery常见经典特效汇总》及《jquery选择器用法总结》

希望本文所述对大家jQuery程序设计有所帮助。

推荐阅读:
  1. 生成和读取XML文件的方法
  2. VBScript读取XML文件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

jquery xml文件 ue

上一篇:jQuery插件DataTables分页开发心得体会

下一篇:JavaScript中最常见的三个面试题解析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》