日期:2014-05-16  浏览次数:20364 次

jquery 读取xml问题
各位大虾,请教个问题,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>

------解决方案--------------------
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>

------解决方案--------------------
楼主通读下jquery的api,很多问题轻松就可以解决。
------解决方案--------------------
探讨

$(this).text(); 为什么拿不到值呢,费解