第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TinyMCE的計數(shù)器無法正常工作

TinyMCE的計數(shù)器無法正常工作

catspeake 2021-05-10 12:14:30
我知道那里有很多解決方案,但無法找到正確的解決方案。我已經(jīng)在tinyMCE版本3中為自定義計數(shù)器編寫了代碼,該版本的maxlength屬性不起作用。我想在計數(shù)器達(dá)到0時停止提供更多文本setcontent(""),substring(0,maxcount)這似乎是有問題的,因為當(dāng)我在其修剪后兩個字符之間輸入任意2個字符時,這種方式不應(yīng)該這樣。我也嘗試過使用evt.preventDefault()它的阻止功能,但無法再次輸入IN進行擊鍵,而擊鍵也排除了bacspace和delete,但它無法正常工作。這是我的代碼。    tinyMCE.init({        mode: "textareas",        theme: "advanced",        editor_selector: "mceEditor",        paste_auto_cleanup_on_paste: 'true',        theme_advanced_disable: 'justifyleft,justifyright,justifyfull,justifycenter,indent,image,anchor,sub,sup,unlink,outdent,help,removeformat,link,fontselect,hr,styleselect,formatselect,charmap,separator,code,visualaid,strikethrough,fullscreen',        theme_advanced_buttons1: 'bold,italic,underline,numlist,bullist,undo,redo,cleanup,spellchecker',        theme_advanced_buttons2: "",        theme_advanced_buttons3: "",        plugins: 'spellchecker,fullscreen,paste',        spellchecker_languages: '+English=en-us',        spellchecker_rpc_url: '<%out.print(request.getContextPath());%>/jazzy-spellchecker',        theme_advanced_statusbar_location: "bottom",        theme_advanced_path : false,        statusbar: true,        setup: function(editor)        {             editor.onKeyUp.add(function(evt)            {                var maxLengthRichTextArea = 5;                 var inputRichTextArea = $(editor.getBody()).text();                 var inputRichTextAreaLength = inputRichTextArea.length;                 var value = maxLengthRichTextArea-inputRichTextAreaLength;                 if(value >= 0)                 {                   $(tinyMCE.activeEditor.getContainer()).find("#"+editor.id+"_path_row").html("Remaining chars: "+(value));                }                              });        }    });</script>的HTML<textarea id="450225" class="mceEditor"  maxlength="10" style="display: none;"></textarea>
查看完整描述

1 回答

?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗 獲得超12個贊

這是您要實現(xiàn)的目標(biāo)的一個有效示例:


HTML:


<textarea id="text"></textarea>

Javascript:


tinymce.init({

  selector: "textarea#text",

  height: 500,

  menubar: false,

  setup: function(editor) {

    var maxlength = 5;

    var allowedKeys = [8, 37, 38, 39, 40];

    editor.on("keydown", function(e) {

      var count = $(editor.getBody()).text().length;

      if(allowedKeys.indexOf(e.which) != -1) {

         return;

      }

      if (count >= maxlength) {

        e.stopPropagation();

        return false;

      }

    });

  }

});

和Codepen,希望對您有所幫助!在我的代碼中,最大長度為5,但是您可以通過var進行更改maxlength。


查看完整回答
反對 回復(fù) 2021-05-27
  • 1 回答
  • 0 關(guān)注
  • 194 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號