How does editable div limit the number of words?

problem description

do a chat editor, you can insert pictures and text, I am using a div,contenteditable set to true, need to limit the text 5000

the environmental background of the problems and what methods you have tried

tried using keypress and keyup,keydown, but the blocking default event of these methods cannot detect Chinese characters. Input can detect Chinese characters, but can"t stop input. If you use the method of replacing the html, value, this method is not easy to implement because of the mixing of graphics and text in the editor, the html tag characters that need to be inserted into html, text and characters such as can not be parsed into HTML.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Apr.28,2021

only limits the total length of Chinese characters and English letters and characters?
if it is that simple, then each time input, the method of detecting the length is triggered, and the last character is not removed if the length is exceeded.
use $('- sharpyoureditor'). Val (). Length ) to judge the length of a Chinese character. In this method, the length of a Chinese character is 1

.
Menu