欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用jquery解析XML的方法

 更新時(shí)間:2014年09月05日 12:02:58   投稿:shichen2014  
這篇文章主要介紹了使用jquery解析XML的方法,代碼簡(jiǎn)潔實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了使用jquery解析XML的方法,分享給大家供大家參考之用。具體方法如下:

一、xml文件結(jié)構(gòu):books.xml

<?xml version="1.0" encoding="UTF-8"?>
<root>
 <book id="1">
  <name>深入淺出extjs</name>
  <author>張三</author>
  <price>88</price>
 </book>
 <book id="2">
  <name>鋒利的jQuery</name>
  <author>李四</author>
  <price>99</price>
 </book>
 <book id="3">
  <name>深入淺出flex</name>
  <author>王五</author>
  <price>108</price>
 </book>
 <book id="4">
  <name>java編程思想</name>
  <author>錢七</author>
  <price>128</price>
 </book>
</root>

二、頁(yè)面代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery解析xml</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
 $(function(){
  $.post('books.xml',function(data){
   //查找所有的book節(jié)點(diǎn)
   var s="";
   $(data).find('book').each(function(i){
    var id=$(this).attr('id');
    var name=$(this).children('name').text();
    var author=$(this).children('author').text();
    var price=$(this).children('price').text();
    s+=id+"&nbsp;&nbsp;&nbsp;&nbsp;"+name+"&nbsp;&nbsp;&nbsp;&nbsp;"+author+"&nbsp;&nbsp;&nbsp;&nbsp;"+price+"<br>";
   });
   $('#mydiv').html(s);
  });
 });
</script>
</head>
<body>
 <div id='mydiv'></div>
</body>
</html>

運(yùn)行效果圖如下:

感興趣的讀者可以點(diǎn)此本站下載完整代碼。

更多關(guān)于jquery xml操作相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery操作xml技巧總結(jié)

相關(guān)文章

最新評(píng)論