如何在ckeditor中给出文本时显示单词计数 [英] How to display the word count while giving text in the ckeditor only

查看:78
本文介绍了如何在ckeditor中给出文本时显示单词计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I need to display the word count while giving the text in ck editor only but with my above code i am able to get the word count on button click.How to display the word count directly while giving text in ck editor instead of button click







<div>
       <ckeditor:ckeditorcontrol id="CKEditor1" basepath="/ckeditor/" runat="server"></ckeditor:ckeditorcontrol>
       <asp:button id="btn1" runat="server" onclick="btn1_Click" text="get word count" />
       <asp:label id="lbl1" runat="server"></asp:label>
   </div>







protected void Page_Load(object sender, EventArgs e)
       {
       }

       protected void btn1_Click(object sender, EventArgs e)
       {
           string whole_text = CKEditor1.Text;
           string trimmed_text = whole_text.Trim();

           // new line split here
           string[] lines = trimmed_text.Split(Environment.NewLine.ToCharArray());

           // don't need this here now...
           //string[] split_text = trimmed_text.Split(' ');

           int space_count = 0;
           string new_text = "";
           foreach (string line in lines)
           {
               // Modify the inner foreach to do the split on ' ' here
               // instead of split_text
               foreach (string av in line.Split(' '))
               {
                   if (av == "")
                   {
                       space_count++;
                   }
                   else
                   {
                       new_text = new_text + av + ",";
                   }
               }
           }

           new_text = new_text.TrimEnd(',');

           // use lines here instead of split_text
           lines = new_text.Split(',');
           //MessageBox.Show(lines.Length.ToString());
           lbl1.Text = lines.Length.ToString();
       }





我尝试过:





What I have tried:

my above code gives the word count on button click instead i need to get the word count while typing the text in ckeditor itself.How can i do this

推荐答案

正如您所看到的,您当前的代码是用C#编写的,所以它在服务器端运行 - 您将要做的事情在JavaScript中重写您的逻辑,然后使用ck事件侦听器逻辑将其绑定到更改逻辑。您可以找到一个监听onChange事件的示例此处 [< a href =https://alfonsoml.blogspot.co.uk/2011/03/onchange-event-for-ckeditor.htmltarget =_ blanktitle =New Window> ^ ]。
As you can see, your current code is written in C#, so it's running on the server side - what you are going to have to do is rewrite your logic in JavaScript and then bind it in to the change logic using the ck event listener logic. You can find an example of listening to the onChange event here[^].






使用CKEditor1的textchange事件。 ontextchange事件写入你在button_click事件中编写的相同逻辑
Hi,

use textchange event of CKEditor1. ontextchange event write the same logic which you have written in button_click event


这篇关于如何在ckeditor中给出文本时显示单词计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆