zoukankan      html  css  js  c++  java
  • Fckeditor编辑器内容长度限制统计实现

    先我们看最简单的就是编辑器的代码了,简单得很同时大家也经常看过。

     代码如下 复制代码
     <script type="text/javascript" src="/editor/fckeditor.js"></script>
     <script type="text/javascript">
        <!--
            var oFCKeditor = new FCKeditor( 'Content' ) ;
            oFCKeditor.BasePath = "/ www.hzhuti.com /" ;
            oFCKeditor.ToolbarSet = "User" ;
            oFCKeditor.Value = '没有最好,只有更好,大家努力' ;
            oFCKeditor.Height = 450 ;
            oFCKeditor.Width = 660 ;
            oFCKeditor.Create() ;
        //-->
        </script>
     
        <input type="button" value="检测字数(包括HTML代码)" style="165px;" class="inputc" onClick="checklength()">
        <script>
     

     //检测在线编器字符数 ,他必须通过创建FCKeditorAPI来实现,代码如下。

     function checklength()
     {
      var Content;
      var oEditor = FCKeditorAPI.GetInstance('Content') ;
      Content=oEditor.GetXHTML(true)
      alert("n当前: "+Content.length+" 个字符");
      return false;
     }
     

     </script>

    再看实例,这里限制了fckeditor编辑器内容的长度哦,

     
    window.onload=function(){

        function FCKeditor_OnComplete()
        {
         var editor = FCKeditorAPI.GetInstance('info') ;
         editor.Events.AttachEvent('OnSelectionChange', editor_keydown);
        }

        function editor_keydown(editor)
        {
            var maxLength=3; //最大输入字数
         content= $(editor.EditorDocument.body).text();
         var len= content.length;
         var $info =$('#info');//存放提示信息
         if(len < maxLength){
          .text("还可以输入 "+(maxLength-len)+"字");
         }
         if(len == maxLength){
          $info.text("字数达到上限");
         }
         if(len > maxLength){
          $info.text(" 输入字符超过"+maxLength+"个,请更改!");
         }
        }
        FCKeditor_OnComplete()
    }
     

    本站原创文章,转载必须注明来源于http://www.111cn.net/wy/yw.html

  • 相关阅读:
    软件测试经典面试题汇总测试…(转载)
    loadrunner录制时弹出invalid application path
    【转】性能测试知多少:性能分析与…(转载)
    loadrunner小知识累积(转载)
    selenium定位方法总结
    [testng]Cannot find class in classpath
    java工程名前有红色感叹号
    jenkins slave节点问题总结
    scrapy爬虫框架
    Python监听鼠标键盘事件
  • 原文地址:https://www.cnblogs.com/phpfans2012/p/2379509.html
Copyright © 2011-2022 走看看