简体   繁体   English

如何在TinyMCE编辑器中以编程方式添加html标签?

[英]How to add html tag programmatically in TinyMCE editor?

I'm using TinyMCE to edit text. 我正在使用TinyMCE编辑文本。 When the user selects some text and presses a button, the selected section should be wrapped with <mark></mark> html tags. 当用户选择一些文本并按下按钮时,所选部分应使用<mark></mark> html标签包裹。

The reason I'm not simply adding a custom text formatting button to the tinymce editor is because I want to trigger other actions to happen with the selected text too (ie copy and paste the text elsewhere). 我之所以不将简单的自定义文本格式设置按钮添加到tinymce编辑器,是因为我也想触发其他操作以使选定的文本发生(即,将文本复制并粘贴到其他位置)。

How can I do this? 我怎样才能做到这一点?

You can add your own custom button to the TinyMCE toolbar and trigger JavaScript when its clicked. 您可以将自己的自定义按钮添加到TinyMCE工具栏,并在单击它时触发JavaScript。 You can then use the editor APIs to wrap the selected text with the tag and perform other work as needed. 然后,您可以使用编辑器API用标记包装所选文本,并根据需要执行其他工作。

Here is a TinyMCE Fiddle that shows the basic process: http://fiddle.tinymce.com/N1gaab 这是显示基本过程的TinyMCE小提琴: http : //fiddle.tinymce.com/N1gaab

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

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