HTML:
Our formula is this: We go out, we hit people in the mouth.<sup id="cite_ref-9" class="reference"><a href="#cite_note-9">[9]</a></sup> The team went 5–4 overall
我试图匹配:
in the mouth. The team went
基本上试图忽略<sup>
标记
我已经改编了this answer的代码。
document.designMode = "on";
var sel = window.getSelection();
sel.collapse(document.body, 0);
while (window.find(search_string)) {
document.execCommand("backColor", false, "yellow");
}
sel.collapseToEnd();
document.designMode = "off";
虽然这会忽略标记,但它不会忽略标记中的文本。
答案 0 :(得分:1)
如果您知道要删除sup
,那么您应该可以执行类似
function stripSupFromText(text) {
var div = document.createElement('div');
div.innerHTML = text;
div.removeChild(div.getElementsByTagName('sup')[0]);
return div.innerText;
}