87,914
社区成员
发帖
与我相关
我的任务
分享
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> new document </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<script type="text/javascript" src="js/jquery.js" ></script>
<script type="text/javascript">
$.ajax({
url:'test.xml',
type: 'get',
datatype: 'xml',//这里可以不写,但千万别写text或者html!!!
timeout: 1000,
error: function(xml){
alert('error loading xml document'+xml);
},
success: function(xml){
alert(xml);
$(xml).find("student").each(function(i){
var id=$(this).children("id"); //取对象
var id_value=$(this).children("id").text(); //取文本
alert(id_value);//这里就是id的值了。
alert($(this).attr("email")); //这里能显示student下的email属性。
//最后么输出了,这个是cssrain的写法,貌似比macnie更jq一点
$("<li></li>").html(id_value +":"+$(this).attr("email")).appendTo("ol");
});
}
});
</script>
<body>
<ol></ol>
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<stulist>
<student email="1@1.com">
<name>zhangsan</name>
<id>1</id>
</student>
<student email="2@2.com">
<name>lisi</name>
<id>2</id>
</student>
</stulist>