我真的在使用Jquery脚本,我无法工作。
我有一个XML字符串,我想从它返回名称'Miki',但它只是不起作用,我无法弄明白。有人能帮助我吗?
function LoadParseXML() {
var xml
xml = '<?xml version="1.0" encoding="utf-8"?><CATALOG><VAR><PREVIOUSPAT>Miki</PREVIOUSPAT></VAR></CATALOG>';
loadXMLDoc(xml, 'PREVIOUSPAT');
}
function loadXMLDoc(url, Node) {
var xmlhttp;
var txt, x, xx, i;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
x = xmlhttp.responseXML.documentElement.getElementsByTagName("VAR");
for (i = 0; i < x.length; i++) {
xx = x[i].getElementsByTagName(Node);
txt = xx[0].firstChild.nodeValue;
alert(txt);
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
答案 0 :(得分:1)
尝试使用此jQuery代码来循环PREVIOUSPAT事件
var xml = '<?xml version="1.0" encoding="utf-8"?><CATALOG><VAR><PREVIOUSPAT>Miki</PREVIOUSPAT></VAR></CATALOG>';
xmlDoc = $.parseXML( xml );
$xml = $( xmlDoc );
$xml.find('CATALOG > VAR > PREVIOUSPAT').each(function(){
alert( $(this).text() );
})