Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 xml 文档。如何通过 Javascript 获取 type="work" 的内容?
<tagname type="job"> <tagname type="work"> <tagname type="home">
以下是使用纯 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); } }
基本上,您需要遍历与标签名称匹配的所有标签,并查找其属性具有正确值的标签。