gpt4 book ai didi

javascript - 从 jquery each 遍历 xml 节点

转载 作者:行者123 更新时间:2023-11-30 13:21:30 25 4
gpt4 key购买 nike

我的html代码是这样的

 <script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.open("GET","brands.xml",false);
xmlhttp.send();
theXmlDoc=xmlhttp.responseXML;
function fillForm(){
$(theXmlDoc).find('table[name=brands]').each(function(){
alert($(this));//doesn't fire when brands.xml contains more than one entry of <table name="brands"> else shows Object object
});

我的 brands.xml 是

  <table name="brands">
<column name="BrandID">1</column>
<column name="BrandName">AX</column>
<column name="CompanyInfo">FDC</column>
<column name="Composition">Cap</column>
</table>
<table name="brands">
<column name="BrandID">2</column>
<column name="BrandName">UP</column>
<column name="CompanyInfo">Tor</column>
<column name="Composition">Asp</column>
</table>

brands.xml包含 <table name="brands"> 的单个条目警报显示 Object 对象,但是当我包含多个表名时,如上所示,每个表名都不会被执行。

最佳答案

您的 XML 需要由单个节点包装:

<tables>
<table name="brands">
<column name="BrandID">1</column>
<column name="BrandName">AX</column>
<column name="CompanyInfo">FDC</column>
<column name="Composition">Cap</column>
</table>
<table name="brands">
<column name="BrandID">2</column>
<column name="BrandName">UP</column>
<column name="CompanyInfo">Tor</column>
<column name="Composition">Asp</column>
</table>
</tables>

并且您需要相应地调整您的 JavaScript,因此请在此包装节点内进行选择。

关于javascript - 从 jquery each 遍历 xml 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10123468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com