callbacks: {
onFocus: function (contents) {
if($('.summernote').summernote('isEmpty')){
$(".summernote").html('');
}
}
}
如果您确定模式,那么您可以实现类似的
var data='<p><br></p><p><br></p><p><strong style="font-family: "Open Sans", Arial, sans-serif; text-align: justify;">Lorem Ipsum</strong><span style="font-family: "Open Sans", Arial, sans-serif; text-align: justify;"> is simply dummy text of the printing and typesetting industry. </span><br></p><p><br></p><p><br></p>';
while(data.startsWith('<p><br></p>')){
data=data.replace('<p><br></p>','')
}
while(data.endsWith('<p><br></p>')){
data=data.replace(new RegExp('<p><br></p>$'),'')
}
console.log(data)
使用以下内容:
$('#summernote').summernote('code', '<text H>');
代替:
$('#summernote').summernote('editor.insertText', '<text H>'));
最好的方法是这样做:
$('.summernote_add').summernote({
height: 250,
callbacks: {
onChange: function (contents) {
if ($('.summernote_add').summernote('isEmpty')) {
$(".add .panel-body").html('');
} else {
$(".add .panel-body").val(contents);
}
// $('.summernote_add').val(
// $('.summernote_add').summernote('isEmpty')
// ? null
// : contents
// );
summernoteValidatorAdd.element($('.summernote_add'));
}
}
});
对于 jQuery
$('.summernote').summernote({
height: 250,
callbacks: {
onInit: function (c) {
c.editable.html('');
}
}
});
只需删除空元素
$("p").each(function(){
if (!$(this).text().trim().length) {
$(this).remove();
}
});
这对我来说有用!必须现在就做
callbacks: {
onFocus: function (contents) {
if($(this).summernote('isEmpty')){
$("<your-selector>").html(''); //either the class (.) or id (#) of your textarea or summernote element
}
}
}
<p><be></p>
,根据文档,这很好。 OnBlur,您只需重置 Summernote,以便它将删除所有其他剩余标签。请参阅此处的文档:
为空
返回编辑器内容是否为空。
即使编辑器内容为空,编辑区域也需要 <p><br></p>
才能获得焦点。所以Summernote支持这个方法来帮助检查编辑器内容是否为空。
onBlur: function (contents) {
if (
$($('#body-summernote').summernote('code')).text().trim().length < 1
) {
console.log(
$($('#body-summernote').summernote('code')).text().trim().length
);
console.log('clearing');
// $('#body-summernote').html('');
$('#body-summernote').summernote('reset');
}
},
let value='<p><br></p><p><br></p><p><strong style="font-family: "Open Sans", Arial, sans-serif; text-align: justify;">Lorem Ipsum</strong><span style="font-family: "Open Sans", Arial, sans-serif; text-align: justify;"> is simply dummy text of the printing and typesetting industry. </span><br></p><p><br></p><p><br></p>';
while(value.startsWith('<p><br></p>') || value.endsWith('<p><br></p>')){
value=value.replace(new RegExp('^<p><br></p>'),'').trim();
value=value.replace(new RegExp('<p><br></p>$'),'').trim();
}