I have a xml document. How can I get content of type="work" by Javascript?
我有一个xml文档。如何通过Javascript获取type =“work”的内容?
<tagname type="job">
<tagname type="work">
<tagname type="home">
1 个解决方案
#1
0
Here's how you could do it with pure javascript.
以下是使用纯javascript进行操作的方法。
var tags = document.getElementsByTagName('tagname');
for (var i = 0; i < tags.length; i++) {
if (tags[i].getAttribute('type') == 'work') {
var content = tags[i].innerHTML;
console.log(content);
}
}
Basically you need to iterate over all the tags matching the tag name and look for the one whose attribute has the correct value.
基本上,您需要迭代匹配标记名称的所有标记,并查找其属性具有正确值的标记。
#1
0
Here's how you could do it with pure javascript.
以下是使用纯javascript进行操作的方法。
var tags = document.getElementsByTagName('tagname');
for (var i = 0; i < tags.length; i++) {
if (tags[i].getAttribute('type') == 'work') {
var content = tags[i].innerHTML;
console.log(content);
}
}
Basically you need to iterate over all the tags matching the tag name and look for the one whose attribute has the correct value.
基本上,您需要迭代匹配标记名称的所有标记,并查找其属性具有正确值的标记。