我的问题是,当我在 SummerNote 中粘贴数据时,会清除格式,但如果我想按照自己的需要格式化粘贴的文本,它不允许我对粘贴的文本或我在编辑器中编写的文本进行更改。 我已使用此代码将 onpaste 事件绑定(bind)到 Summernote。
我使用的是 Summernote.js 版本 0.5.8
$(".summernote").summernote({
onpaste: function (e) {
debugger;
var bufferText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text');
e.preventDefault();
setTimeout(function () {
document.execCommand('insertHTML', false, bufferText);
}, 10);
}
})
最佳答案
在 html 文件中使用 on-paste 属性
<div summernote="rules"
ng-model="league.rules"
validate-summernote="checkLeagueRules"
config="summernote_options"
on-paste="removeFormatting(evt)"
class="summernote"
></div>
在 Controller 中使用removeFormatting函数
$scope.removeFormatting = function(e)
{
var bufferText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text');
e.preventDefault();
// Firefox fix
setTimeout(function () {
document.execCommand('insertText', false, bufferText);
}, 10);
}
关于javascript - Summernote 不允许在写入 onpaste 事件后格式化粘贴的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33799909/