如何在<br>
标签之间选择一些东西,使用 xpath 或者建议其他解决方案。到目前为止,这是我选择的代码,<p>
但我需要<br>
标签之间的内容:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>some text <br>select this </br>and not this</p>
<div id="insert"></div>
<script>
data = document;
var headings = data.evaluate("//p", data, null, XPathResult.ANY_TYPE, null);
var thisHeading = headings.iterateNext();
var selectedText = "Selected: <br>";
while (thisHeading) {
selectedText += thisHeading.textContent + "<br>";
thisHeading = headings.iterateNext();
}
document.getElementById('insert').innerHTML = selectedText;
</script>
</body>
</html>