我正在编写一个 Greasemonkey 脚本,其中在一个地方我将文本中的所有空格转换为<br>
,以便字符串在表格中的单元格中显得更加垂直。
我匹配的 HTML 是:
<span>
<img class="icon itemicon" alt="Manual item" ...etc...>
Chapter 2 reading
<a title="Sort in descending order" href="index.php....."> etc </a>
</span>
这是我的代码:
var child = spanelm.firstChild;
var textChild = child.nextSibling;
textChild.textContent = textChild.textContent.replace(/ /g, "<br>");
我的 Greasemonkey 脚本找到了正确的元素并成功进行了更改,但在网页上我看到了<br>
字面上的标签:
Chapter<br>2<br>reading
(在我的代码的另一个地方,我正在做类似的事情,这似乎有效:
spanelm.firstChild.innerHTML = spanelm.firstChild.text.replace(/ /g, "<br>");
但我无法在这种情况下使用这种 HTML 组织。)
我觉得我需要告诉 Greasemonkey eval()
HTML 什么的......