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

解决方案 »

  1.   

    <!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>
      

  2.   

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

  3.   

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

  4.   


    因为注释的节点类型是注释节点(nodeType == 8),而不是文本节点(nodeType == 3)