如何在 WordPress 中使用 jQuery 操作 tinyMCE 内容?
How to manipulate tinyMCE content using jQuery in WordPress?
在过去的两天里,我一直在寻找一种在 WordPress 中使用自定义按钮来操作 tinyMCE 内容的方法。使用 editor.getBody()
,我能够轻松获取内容并对其进行操作,但我不知道如何获取光标位置或所选元素。我尝试了 getContent
,但表现不同。
我正在做的是:当用户单击自定义按钮时,我需要找到它的特定父元素,然后对其进行操作。有什么办法可以做到吗?
是的,这行得通。
您可以使用设置 tinymce 配置参数:
setup : function(ed) {
ed.on('init', function(e){
$(ed.getBody()).bind('change', function(e) {
// do your magic here if e.target is your button!
});
});
}
在编辑器中获取插入符节点的另一种方法是调用:
tinymce.get('your_editor_id').selection.getNode();
在过去的两天里,我一直在寻找一种在 WordPress 中使用自定义按钮来操作 tinyMCE 内容的方法。使用 editor.getBody()
,我能够轻松获取内容并对其进行操作,但我不知道如何获取光标位置或所选元素。我尝试了 getContent
,但表现不同。
我正在做的是:当用户单击自定义按钮时,我需要找到它的特定父元素,然后对其进行操作。有什么办法可以做到吗?
是的,这行得通。 您可以使用设置 tinymce 配置参数:
setup : function(ed) {
ed.on('init', function(e){
$(ed.getBody()).bind('change', function(e) {
// do your magic here if e.target is your button!
});
});
}
在编辑器中获取插入符节点的另一种方法是调用:
tinymce.get('your_editor_id').selection.getNode();