我正在做一些页面突出显示,并发现使用文本选择和添加跨度时最流行的例子是切换到designMode并运行execCommand
关于如何在创建后删除span标记没有后续内容.我看到了一些使用jquery和replaceWith的例子,但没有使用直接的javascript.
你应该可以这样做:
// Where span is a reference to the span to be replaced
var text = span.textContent || span.innerText;
var node = document.createTextNode(text);
span.parentNode.replaceChild(node, span);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2446 次 |
| 最近记录: |