【发布时间】:2020-08-19 16:40:29
【问题描述】:
我有一个按钮,点击它时我想在编辑器中添加一些文本。
我看到了一些人们给出解决方案的问题,我尝试了一下。但是当我将 restoreRange 和 execCmd 与 insertHTML 一起使用时,它不会在插入符号处插入,只有在之前在编辑器中输入了某些内容时,例如一个字符或一个空格。
换句话说,当点击编辑器时,它不会在我点击时插入插入符号的位置,但在写东西时,它会。
就像 restoreRange 只在写东西时起作用。
问题发生在以下代码中:
$('#editor').trumbowyg({
btnsDef: {
testButton: {
fn: function () {
// Restore the previous position
$("#editor").trumbowyg('restoreRange');
// Add text in the current position
$("#editor").trumbowyg('execCmd',
{
cmd: 'insertHTML',
param: 'Dummy text',
forceCss: false
});
},
title: 'test button',
text: 'insert text',
hasIcon: false
}
},
btns: [
['testButton'],
]
});
在这里重现问题: https://jsfiddle.net/95nqv076/
我错过了什么吗?
【问题讨论】: