52,797
社区成员
发帖
与我相关
我的任务
分享
……
$(xml).find("x").each(function(){
alert("hi");
});
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312">
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<title>测试</title>
<script language="javascript">
$(function(){
$("#test").click(function(){
$.ajax({
type: "GET",
url: "test.asp",
dataType: "xml",
success: function(xml){
var n=0;
$(xml).find("x").each(function(){n++;});
alert("n="+n);
},
error: function(){alert("error")}
});
});
});
</script>
</head>
<body>
<input type="button" value="测试" name="test" id="test">
</body>
</html>
<%
result="<?xml version=""1.0"" standalone=""yes"" encoding=""gb2312""?>"
result=result&"<y><x></x><x></x></y>"
Response.Charset="gb2312"
Response.ContentType="text/xml"
Response.Write result
%>
$(xml).find('t').each(
function(){
$(this).find('teacher').each(
function(){
// do something here
}
);
});
$(function(){
GetXmlDoc.Read("treeview.xml");
});
var GetXmlDoc={
Read:function(filePath)
{
$.ajax({
type: "GET",
url: filePath,
dataType: "xml",
success: function(xml){GetXmlDoc.HandXml(xml);}
});
},
HandXml:function(xml)
{
var a=0;
var b=0;
var result="";
$(xml).find('List').each(
function(){
$(this).find('CB').each(
function()
{
a ++;
result += "<li id='CB_"+a+"' onclick=\"javascript:$('#CB_ul_"+a+"').toggle('slow');\">"+$(this).attr('cname')+ "("+$(this).attr('cid')+")</li>"+"<ul id='CB_ul_"+a+"' style=\"display:none\">";
$(this).find('CS').each(
function(){
b++;
result +="<li id='CB_"+a+"_"+b+"'>"+$(this).attr('cname')+"("+$(this).attr('cid')+")</li>";
}
);
result +="</ul>";
}
);
}
);
setTimeout(function(){
$('#ul_id').html(result).show('slow');
},2000);
}
};
<?xml version="1.0" encoding="utf-8" ?>
<List>
<CB cname="北京" cid="1">
<CS cname="北京" cid="364">北京市</CS>
</CB>
<CB cname="天津" cid="2">
<CS cname="天津" cid="365">天津市</CS>
</CB>
<CB cname="北京" cid="1">
<CS cname="北京" cid="364">北京市</CS>
</CB>
<CB cname="天津" cid="2">
<CS cname="天津" cid="365">天津市</CS>
</CB>
<CB cname="北京" cid="1">
<CS cname="北京" cid="364">北京市</CS>
</CB>
<CB cname="天津" cid="2">
<CS cname="天津" cid="365">天津市</CS>
</CB>
<CB cname="北京" cid="1">
<CS cname="北京" cid="364">北京市</CS>
</CB>
<CB cname="天津" cid="2">
<CS cname="天津" cid="365">天津市</CS>
</CB>
<CB cname="北京" cid="1">
<CS cname="北京" cid="364">北京市</CS>
</CB>
<CB cname="天津" cid="2">
<CS cname="天津" cid="365">天津市</CS>
</CB>
<CB cname="北京" cid="1">
<CS cname="北京" cid="364">北京市</CS>
</CB>
<CB cname="天津" cid="2">
<CS cname="天津" cid="365">天津市</CS>
</CB>
<CB cname="北京" cid="1">
<CS cname="北京" cid="364">北京市</CS>
</CB>
</List>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312">
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<title>测试</title>
<script language="javascript">
$(function(){
$("#test").click(function(){
var xml1="<?xml version=\"1.0\" standalone=\"yes\" encoding=\"gb2312\"?><y><x></x></y>"
var xml2="<?xml version=\"1.0\" standalone=\"yes\" encoding=\"gb2312\"?><a><x></x></a>"
var x1=x2=0;
// .children("x")和.find("x")在此处运行效果相同
$(xml1).children("x").each(function(){x1++;});
$(xml2).children("x").each(function(){x2++;});
alert("x1="+x1+", x2="+x2);
});
});
</script>
</head>
<body>
<input type="button" value="测试" name="test" id="test">
</body>
</html>