简体   繁体   English

JavaScript document.execCommand()拥有自己的标签

[英]JavaScript document.execCommand() own tags

I've found some really interesting! 我发现一些非常有趣! The execCommand function applies many useful features. execCommand函数应用了许多有用的功能。 But is it possible to work with OWN wraps? 但是可以使用OWN包裹吗? Like: 喜欢:

document.execCommand("styleWithCSS", false, "<span class='own-class'>");

Everything related i've found was pretty old… so maybe one of you knows a good workaround or something. 我发现的所有相关内容都很古老......所以也许你们其中一个人知道一个好的解决方法或者什么。

Thanks to dandavis. 感谢dandavis。

The following works very well: 以下工作非常好:

document.execCommand("insertHTML", false, "<span class='own-class'>"+ document.getSelection()+"</span>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM