gpt4 book ai didi

summernote - 如何限制summernote中文本区域的字数

转载 作者:行者123 更新时间:2023-12-02 20:22:56 25 4
gpt4 key购买 nike

我正在尝试限制夏日笔记中允许的字数。

例如,我只想限制最多 50 个字。

你有什么想法吗?

$(document).ready(function() {
$('#summernote').summernote({
height: 20,
});
});

最佳答案

我想为这篇文章做出贡献,因为这帮助我找到了我想要的解决方案。看来建议的答案尚未被接受。

我为 maxLength 创建了一个变量,以下是我配置 Summernote 回调的方式。请注意,我使用的 Summernote 版本的编辑区域为 .note-editable。下面的解决方案是 typescript ,我有一个目标范围,它显示剩余的字符数。

callbacks: {
onKeydown(e) {

// The text method will ignore HTML tags and preserve non-breaking
// space allowing for a true character count

let content: string = $('.note-editable').text();

// This checks if the character is alphanumeric (i.e. not a backspace or return key)

let isCharacter: boolean = (/[a-zA-Z0-9-_ ]/.test(String.fromCharCode(e.keyCode)));

// If the current content length is at max, preventDefault will disallow
// any more characters

if (isCharacter) {
if (content.length >= maxLength) {
e.preventDefault();
}
}
},
onKeyup(e) {

// After the result of checking the character and max length exceeded,
// take the resulting count and determine and display characters remaining

let content: string = $('.note-editable').text();
let charactersRemaining: number = maxLength - content.length;
$('#SomeDivId span').text(charactersRemaining);
}

关于summernote - 如何限制summernote中文本区域的字数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35796758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com