需要粘贴帮助的tinyMCE字计数器
大家早上好,希望你们玩得开心,首先我要感谢你们对我的问题的快速答复,不久前我需要一个 TinyMCE 的字计数器,我得到了一些很好的回应,这个我希望当用户剪切并粘贴到计数器中时,它也应该对单词进行计数并相应地限制它们,这是按键计数器的代码
tinyMCE.init({
mode : "textareas",
elements : "teaser,headline",
setup: function(ed) {
var text = '';
var span = document.getElementById('word-count');
if(span)
{
var wordlimit = span.innerHTML;
ed.onKeyDown.add(function(ed, e) {
text = ed.getContent().replace(/(< ([^>]+)<)/g, '').replace(/\s+/g, ' ');
text = text.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
wordcount = wordlimit - (text.split(' ').length);
span.innerHTML = wordcount;
if(wordcount <= 0 && e.keyCode != 8)
{
return tinymce.dom.Event.cancel(e);
}
});
}
}
})
请您帮我修改它,以便我也可以在粘贴时进行监视。谢谢。 @cyberomin。
Good morning people, hope y'all are having a good time, first and foremost i want to thank y'all for your speedy response to my questions, a while ago i need a word counter for tinymce and i got some good response, this time i want when a user cut and paste into the counter it should also count the words and restrict them accordingly, here is the code to the onkey press counter
tinyMCE.init({
mode : "textareas",
elements : "teaser,headline",
setup: function(ed) {
var text = '';
var span = document.getElementById('word-count');
if(span)
{
var wordlimit = span.innerHTML;
ed.onKeyDown.add(function(ed, e) {
text = ed.getContent().replace(/(< ([^>]+)<)/g, '').replace(/\s+/g, ' ');
text = text.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
wordcount = wordlimit - (text.split(' ').length);
span.innerHTML = wordcount;
if(wordcount <= 0 && e.keyCode != 8)
{
return tinymce.dom.Event.cancel(e);
}
});
}
}
})
please can you help modify it for me to also watch for on paste. Thank you.
@cyberomin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

这是相当前瞻性的:
That is pretty forward: