下面是我的代码,它给出按钮点击时的单词计数,但是当我在ck编辑器中输入时,我需要直接显示单词计数而不是显示单词计数。我怎么能这样做。我能得到按钮点击计数但我需要在输入时显示相同的计数
HTML code:
<body>
<form id="form1" runat="server">
<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>
</form>
</body>
C#代码:
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(',');
答案 0 :(得分:0)
您需要向CK编辑器添加事件处理程序 文档示例:
var editor = CKEDITOR.replace( 'editor1' );
// The "change" event is fired whenever a change is made in the editor.
editor.on( 'change', function( evt ) {
// getData() returns CKEditor's HTML content.
console.log( 'Total bytes: ' + evt.editor.getData().length );
});