用于在AjaxTool编辑器中计算字符的Javascript

时间:2016-07-20 17:35:33

标签: javascript jquery asp.net ajaxcontroltoolkit rich-text-editor

我是javascript和ASP .NET的新手。我已经浏览了这个链接,它显示了我们如何计算ajaxtools编辑器中的字符。

Ajax Html Editor is not counting characters in master page using ASP.NET C#

这是我的页面:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="abstractDetails.aspx.cs" Inherits="RA.Apps.abstractDetails" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor" TagPrefix="cc1" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolKit" %>
<asp:Content ID="main" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="content" ContentPlaceHolderID="MainContent" runat="server">

 <script type="text/javascript">

         var Editor1 = '#Editor1';
         var Editor1CountLimit = 30
         var Editor1InfoArea = '#Info';

         $(document).ready(function () {
             TrackCharacterCount(Editor1, Editor1CountLimit, Editor1InfoArea);
         });

         function TrackCharacterCount(ctl, limit, info) {
             var editor = $(ctl).contents().find('iframe').eq(2);
             $(editor).load(function () {
                 var txt = $(this).contents().find('body').text();
                 $(info).html(txt.length); //set initial value 
                 $(this).contents().keyup(function () {
                     var txt = $(this).contents().find('body').text();

                     if (txt.length > limit)
                         $(info).html(txt.length).css("color", "red");
                     else
                         $(info).html(txt.length).css("color", "");
                 });
             });
         }

         function ValidateEditor1Length(source, args) {
             var editor = $(Editor1).contents().find('iframe').eq(2);
             var txt = editor.contents().find('body').text();
             var isValid = txt.length > 0 && txt.length <= Editor1CountLimit;
             args.IsValid = isValid;
         }

</script> 

 <div class="table-row">
    <div class="table-col">
        <div id="Info">Info</div>                                                              
            <cc1:Editor ID="Editor1" width="850px" runat="server" />
            <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="Editor1" ClientValidationFunction="ValidateEditor1Length" ErrorMessage="Exceeded Character Limit"></asp:CustomValidator>
    </div>
 </div>

但它没有显示字符数。任何人都可以帮助我。

0 个答案:

没有答案