<返回更多

jquery 读取xml文件

2019-12-09    
加入收藏
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/JAVAscript" src="js/jquery-3.3.1.min.js"></script>
		<script type="text/JavaScript">
		$(function(){
			$.get("xml/test.xml", function(data){
				var book_list = $(data).find('book');
				
				var book_length = book_list.length;
				var i = 0;
				var range;
				var author;
				var target;
				book_list.each(function(index, value){
					
					range = $(this).children('range').text();
					author = $(this).children('author').text();
					target = $(this).children('target').text();
					
					console.log(range+' '+author+' '+target);
					
				});
			},'xml');
		});
		</script>
	</head>
	<body>
	</body>
</html>
<!--
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
 <book>
 <range>前端专区1</range>
 <author>蚂蚁部落</author>
 <target>css教程</target>
 </book>
 <book>
 <range>前端专区</range>
 <author>蚂蚁部落</author>
 <target>div教程</target>
 </book>
 <book>
 <range>资源专区</range>
 <author>softwhy.com</author>
 <target>特效下载</target>
 </book>
 <book>
 <range>前端专区</range>
 <author>softwhy.com</author>
 <target>教程下载</target>
 </book>
</bookstore>
-->
声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>