需要粘贴帮助的tinyMCE字计数器

发布于 10-06 23:09 字数 814 浏览 9 评论 0原文

大家早上好,希望你们玩得开心,首先我要感谢你们对我的问题的快速答复,不久前我需要一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸伞微斜2024-10-13 23:09:24

这是相当前瞻性的:

ed.onPaste.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);
  }
});

That is pretty forward:

ed.onPaste.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);
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文