http://jsbin.com/eyeqer/2/edit
var x = document.evaluate('//p/following-sibling::text()', document, null, XPathResult.ANY_TYPE, null);
var theTitle = x.iterateNext();
while (theTitle){
alert(theTitle.textContent);
theTitle = x.iterateNext();
}
和
<body>
<p>Hello</p>
<p>World</p>
<p>HW</p>
</body>
我希望看到“世界”和“硬币”,但它没有用!为什么?我该如何解决?
答案 0 :(得分:3)
您需要选择节点,因此您应该使用*
,而不是text()
。
var x = document.evaluate('//p/following-sibling::*', document, null, XPathResult.ANY_TYPE, null);