此处为 Jsfiddle 示例:
http://jsfiddle.net/w0ap9Lun/1/
我的目标是选择 TinyMCE 文本区域的所有内容并将其复制到剪贴板(相当于全部突出显示并按 ctrl+c)。
我可以像这样使用普通输入来做到这一点:
$('.copyToclip').on('click', function() {
//select the input
$(this).siblings('input').select();
//fire the copy command
document.execCommand("copy");
$(this).text('copied');
});
以下代码选择了编辑器中的所有内容,但是当我调用“execCommand("copy")”时,它没有被复制到剪贴板,这是我的代码:
$('.copyTinyMCEToclip').on('click', function() {
//select the content of the active tinyMCE instance
tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody());
document.execCommand("copy");
$(this).text('copied');
});
如有任何帮助,我们将不胜感激。
最佳答案
你可以使用 tinyMCE 方法吗,试试这个:
jQuery(function(){
jQuery('.copyTinyMCEToclip').click(function(){
var selectedText = tinyMCE.activeEditor.selection.getContent();
jQuery('input').attr('value', selectedText);
});
});
示例:http://jsfiddle.net/w0ap9Lun/2/
引用:http://archive.tinymce.com/wiki.php/API3:method.tinymce.dom.Selection.getContent
关于jquery - 将 TinyMCE 编辑器的选定内容复制到剪贴板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41698411/