郑德才博客 记录学习,记录工作,学习知识分享!

Asp.Net FCKeditor文本编辑器当输入文字时,判断输入的文本长度

   
<script type="text/javascript">
    //FCK会自动加载此函数
    function FCKeditor_OnComplete(editorInstance) {
        //editorInstance.Events.AttachEvent("onkeydown",checkMaxInput);  //删除的时候
        editorInstance.EditorDocument.attachEvent("onkeypress", checkMaxInput1);  //输入的时候执行获取文本长度
        editorInstance.Events.AttachEvent('OnSelectionChange', checkMaxInput); //改变文本内容的时候执行获取文本长度
        //  editorInstance.Events.AttachEvent('OnBlur', checkMaxInput); //附加失去焦点的事件
    }
    //检查输入框的情况
    function checkMaxInput1() {
        countC.innerText = FCKeditorAPI.GetInstance("InfoText").EditorDocument.body.innerText.length + 1;
    }
    function checkMaxInput() {
        countC.innerText = FCKeditorAPI.GetInstance("InfoText").EditorDocument.body.innerText.length;
    }

</script>

<fckeditorv2:fckeditor id="SmsInfoText" runat="server" DefaultLanguage="zh-cn" Width="538" ></fckeditorv2:fckeditor>

使用asp.net的Label获取当前文本长度:已经输入<asp:Label ID="countC" runat="server" Text="0" ForeColor="red"></asp:Label>个字。

2012年5月9日 | 发布:郑德才博客 | 分类:学习之路 | 评论:0

发表留言: