JavaScript document.execCommand() own tags

邮差的信 提交于 2019-11-30 11:59:08

问题


I've found some really interesting! The execCommand function applies many useful features. But is it possible to work with OWN wraps? 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.


回答1:


Thanks to dandavis.

The following works very well:

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


来源:https://stackoverflow.com/questions/16529316/javascript-document-execcommand-own-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!