在 XML 中:
<elements>
<product id="1">
<brand>xxxxxxx</brand>
<dci>xxxxx</dci>
<therapeutic_area>xxxxxx</therapeutic_area>
</product>
<product id="2">
<brand>xxxxxx</brand>
<dci>xxxx</dci>
<therapeutic_area>xxxx</therapeutic_area>
</product>
<product id="3">
<brand>xxx</brand>
<dci>xxxx</dci>
<therapeutic_area>xxxxx</therapeutic_area>
</product>
我需要选择具有特定属性值的节点。例如2
我尝试了这个,但它不起作用:
alert(xmlDoc.getElementsByTagName("product")[0].getAttributeNode("2"));
预先感谢您的帮助
最佳答案
尝试这样
var list=xmlDoc.getElementsByTagName("product");
for (i=0;i<list.length;i++)
{
if(list[i].getAttribute("id")==2){
// Found your node
}
}
关于javascript - 在javascript中选择具有特定属性值的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30757317/