Asp.net中Ajax编辑器的字符数

问题描述:

我在页面中使用了HTML EDITOR来获取用户的文章。我需要在编辑器上计算用户输入的字符数量.....并修改编辑器中的总字符数......我怎么能这样做?

I have used HTML EDITOR in my page for Getting article from user. I need to count the no of characters entered by user on a editor..... And fix the total characters on a editor.....How can i do that?

<%@ Page Language="VB" AutoEventWireup="false" %>


<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc2" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>


        <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </cc1:ToolkitScriptManager>


        <asp:UpdatePanel ID="updatePanel1" runat="server">
            <ContentTemplate>
               <cc2:Editor ID="myEditor" runat="server"Height="400px" />
               <asp:Button runat="server" Text="Submit content" ID="submit" />
               <br />
               <br />
               <span>
                   HTML:<input type="text" readonly="readonly" id="totalHtml"  value=""/>
                   Text:<input type="text" readonly="readonly" id="totalPlain" value=""/>
               </span>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
<script type="text/javascript">


    // on Application load
    Sys.Application.add_load(function() {
        var editor =


find( <%= myEditor .ClientID%>); // 编辑ID =myEditor
var editPanel = editor.get_editPanel();
var designPanel = editPanel.get_modePanels()[AjaxControlToolkit.HTMLEditor.ActiveModeType.Design];


editPanel._setActive_saved = editPanel._setActive;
editPanel._setActive = function (){
if this .get_activeMode()== AjaxControlToolkit.HTMLEditor.ActiveModeType.Design){
var designPanel = 此跨度> .get_activePanel();
designPanel.onContentChanged();
}
._ setActive_saved();
};


designPanel.onContentChanged = function (){
var innerText;


if (AjaxControlToolkit.HTMLEditor.isIE){
innerText = 此跨度> ._ doc.body.innerText;
} 其他 {
var div1 = document .createElement( div);
var html = new AjaxControlToolkit.HTMLEditor.jsDocument(真跨度>);
AjaxControlToolkit.HTMLEditor .__ MozillaGetInnerText(div1,html);
innerText = html.toString();
delete div1;
delete html;
}


// HTML文字长度
var htmlTextLength = AjaxControlToolkit.HTMLEditor.Trim( this ._ doc.body.innerHTML)。长度;


// 纯文本长度
var
plainTextLength = innerText.replace(/ ^ [\ s] + / g, )。replace(/ [\s] +
find("<%= myEditor.ClientID %>"); // Editor's ID="myEditor" var editPanel = editor.get_editPanel(); var designPanel = editPanel.get_modePanels()[AjaxControlToolkit.HTMLEditor.ActiveModeType.Design]; editPanel._setActive_saved = editPanel._setActive; editPanel._setActive = function() { if (this.get_activeMode() == AjaxControlToolkit.HTMLEditor.ActiveModeType.Design) { var designPanel = this.get_activePanel(); designPanel.onContentChanged(); } this._setActive_saved(); }; designPanel.onContentChanged = function() { var innerText; if (AjaxControlToolkit.HTMLEditor.isIE) { innerText = this._doc.body.innerText; } else { var div1 = document.createElement("div"); var html = new AjaxControlToolkit.HTMLEditor.jsDocument(true); AjaxControlToolkit.HTMLEditor.__MozillaGetInnerText(div1, html); innerText = html.toString(); delete div1; delete html; } // HTML text length var htmlTextLength = AjaxControlToolkit.HTMLEditor.Trim(this._doc.body.innerHTML).length; // Plain text length var plainTextLength = innerText.replace(/^[\s]+/g, "").replace(/[\s]+


/ g, )。replace(/ [\ s] + / g, )。length;


// 将代码放在此处:
document .getElementById( totalHtml ).value = htmlTextLength;
document .getElementById( totalPlain).value = plainTextLength;
}
});


< / script >
< / html >
/g, "").replace(/[\s]+/g, " ").length; // Place here your code: document.getElementById("totalHtml").value = htmlTextLength; document.getElementById("totalPlain").value = plainTextLength; } }); </script> </html>





Don不要忘记将这篇文章标记为答案,如果它对你有所帮助......



谢谢



快乐编码...



Don''t forget to mark this post as answer, if it helped you...

Thanks

Happy Coding...