Jquery 所见即所得内容可编辑编辑器-如何设置富文本编辑器的maxlength

Jquery 所见即所得内容可编辑编辑器-如何设置富文本编辑器的maxlength,jquery,wysiwyg,Jquery,Wysiwyg,我正在使用wysiwyg contenteditable editor-i wan将富格文本编辑器的最大长度设置为200,如果我在textarea中给出maxlength=“200”不起作用,因为它是以div的html格式生成的,class=“wysiwyg editor”,那么如何修复此组件的maxlength HTML: JS: $('.richTextEditor01')。每个(函数(索引,元素) { $(元素).wysiwyg({ 课程:“更多的课程”, //“选择”|“顶部”|“顶

我正在使用wysiwyg contenteditable editor-i wan将富格文本编辑器的最大长度设置为200,如果我在textarea中给出maxlength=“200”不起作用,因为它是以div的html格式生成的,class=“wysiwyg editor”,那么如何修复此组件的maxlength

HTML:


JS:

$('.richTextEditor01')。每个(函数(索引,元素)
{
$(元素).wysiwyg({
课程:“更多的课程”,
//“选择”|“顶部”|“顶部选择”|“底部选择”|“底部选择”
//工具栏:索引==0?'top selection':(索引==1?'bottom':'selection'),
按钮:{
//Fontsize插件
字体大小:{
标题:“尺寸”,
图像:“”,
弹出:功能($popup,$button){
//参考:http://stackoverflow.com/questions/5868295/document-execcommand-fontsize-in-pixels/5870603#5870603
变量列表_fontsizes=[];
对于(var i=8;i我之前发布了一个。答案是,您真的不应该限制富格文本编辑器的长度。HTML是由富格文本编辑器动态生成的,因此您不能真正限制输入内容。您可以从技术上限制输出HTML的长度,但这样做可能会导致格式错误的HTML,而这不会影响到您n/正确渲染。虽然这似乎不是答案,但最好不要限制输入,而是确保可以在后端处理输入(如果保存到数据库等)

<textarea name="Processing" maxlength="10" class="richTextEditor01" placeholder="Type your text here..."></textarea>
  $('.richTextEditor01').each( function(index, element)
    {
        $(element).wysiwyg({
            classes: 'some-more-classes',
            // 'selection'|'top'|'top-selection'|'bottom'|'bottom-selection'
           // toolbar: index == 0 ? 'top-selection' : (index == 1 ? 'bottom' : 'selection'),
            buttons: {

                // Fontsize plugin
                fontsize: {
                    title: 'Size',
                    image: '<img src="theme/db/img/icon_rte_fontSize.png" width="18" height="18" alt="Font Size" />', 
                    popup: function( $popup, $button ) {
                            // Refer: http://stackoverflow.com/questions/5868295/document-execcommand-fontsize-in-pixels/5870603#5870603
                            var list_fontsizes = [];
                            for( var i=8; i <= 11; ++i )
                                list_fontsizes.push(i+'px');
                            for( var i=12; i <= 28; i+=2 )
                            list_fontsizes.push(i+'px');
                            list_fontsizes.push('36px');
                            list_fontsizes.push('48px');
                            list_fontsizes.push('72px');
                            var $list = $('<div/>').addClass('wysiwyg-toolbar-list')
                                                   .attr('unselectable','on');
                            $.each( list_fontsizes, function( index, size ){
                                var $link = $('<a/>').attr('href','#')
                                                    .html( size )
                                                    .click(function(event){
                                                        $(element).wysiwyg('shell').fontSize(7).closePopup();
                                                        $(element).wysiwyg('container')
                                                                .find('font[size=7]')
                                                                .removeAttr("size")
                                                                .css("font-size", size);
                                                        // prevent link-href-#
                                                        event.stopPropagation();
                                                        event.preventDefault();
                                                        return false;
                                                    });
                                $list.append( $link );
                            });
                            $popup.append( $list );
                           }
                    //showstatic: true,    // wanted on the toolbar
                    //showselection: true    // wanted on selection
                },
                bold: {
                    title: 'Bold (Ctrl+B)',
                    image: '<img src="theme/db/img/icon_rte_Bold.png" width="18" height="18" alt="Bold" />', 
                    hotkey: 'b'
                },
                italic: {
                    title: 'Italic (Ctrl+I)',
                    image: '<img src="theme/db/img/icon_rte_Italic.png" width="18" height="18" alt="Italic" />',
                    hotkey: 'i'
                },
                underline: {
                    title: 'Underline (Ctrl+U)',
                    image: '<img src="theme/db/img/icon_rte_Underline.png" width="19" height="19" alt="Underline" />', 
                    hotkey: 'u'
                },
                forecolor: {
                    title: 'Text color',
                    image: '<img src="theme/db/img/icon_rte_fontColor.png" width="19" height="19" alt="Text Color" />' 
                },
                removeformat: {
                    title: 'Remove format',
                    image: '\uf12d' 
                }
            }

    });

}