各位大虾,请教个问题,jquery 读取xml 比如我要获取 属性bind是userCode 的bop节点,怎么快速获取到,而不是用循环一个个节点比较获取<bo xmlns="http://www.w3.org/1999/xhtml" operationstatus="init" userid="0" index="1">
<bop bind="id"><!--[CDATA[780]]--></bop>
<bop bind="userName"><!--[CDATA[管理员]]--></bop>
<bop bind="userNameEn"><!--[CDATA[system]]--></bop>
<bop bind="userCode"><!--[CDATA[system]]--></bop>
</bo>
<bop bind="id"><!--[CDATA[780]]--></bop>
<bop bind="userName"><!--[CDATA[管理员]]--></bop>
<bop bind="userNameEn"><!--[CDATA[system]]--></bop>
<bop bind="userCode"><!--[CDATA[system]]--></bop>
</bo>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
</head><body>
<script type="text/javascript">
var xml = '<bo xmlns="http://www.w3.org/1999/xhtml" operationstatus="init" userid="0" index="1">\
<bop bind="id"><!--[CDATA[780]]--></bop>\
<bop bind="userName"><!--[CDATA[管理员]]--></bop>\
<bop bind="userNameEn"><!--[CDATA[system]]--></bop>\
<bop bind="userCode"><!--[CDATA[system]]--></bop>\
</bo>';
xml = $($.parseXML(xml));
xml.find("bop[bind='userCode']").each( function() {
alert($(this).html());
});
</script>
</body>
</html>
因为注释的节点类型是注释节点(nodeType == 8),而不是文本节点(nodeType == 3)