标题 | 使用jquery解析XML示例代码 |
范文 | 易贤网网校上线了! >>>点击进入<<< 网校开发及拥有的课件范围涉及公务员、财会类、外语类、外贸类、学历类、 职业资格类、计算机类、建筑工程类、等9大类考试的在线网络培训辅导。 xml文件结构:books.xml view sourceprint?01 <?xml version="1.0" encoding="UTF-8"?> 02 <root> 03 <book id="1"> 04 <name>深入浅出extjs</name> 05 <author>张三</author> 06 <price>88</price> 07 </book> 08 <book id="2"> 09 <name>锋利的jQuery</name> 10 <author>李四</author> 11 <price>99</price> 12 </book> 13 <book id="3"> 14 <name>深入浅出flex</name> 15 <author>王五</author> 16 <price>108</price> 17 </book> 18 <book id="4"> 19 <name>java编程思想</name> 20 <author>钱七</author> 21 <price>128</price> 22 </book> 23 </root> 页面代码: view sourceprint?01 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 02 <html> 03 <head> 04 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 05 <title>jquery解析xml</title> 06 <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> 07 <script type="text/javascript"> 08 $(function(){ 09 $.post('books.xml',function(data){ 10 //查找所有的book节点 11 var s=""; 12 $(data).find('book').each(function(i){ 13 var id=$(this).attr('id'); 14 var name=$(this).children('name').text(); 15 var author=$(this).children('author').text(); 16 var price=$(this).children('price').text(); 17 s+=id+" "+name+" "+author+" "+price+"<br>"; 18 }); 19 $('#mydiv').html(s); 20 }); 21 }); 22 </script> 23 </head> 24 <body> 25 <div id='mydiv'></div> 26 </body> 27 </html> |
随便看 |
|
在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。