剩下TinyMCE字符

时间:2014-03-07 13:06:55

标签: javascript php tinymce

我正在尝试将字符留在textarea中。但它不起作用。我的剧本:

<script type="text/javascript">
function updateCountdown() {
    // 140 is the max message length
    var remaining = 300 - jQuery('.short').val().length;
    jQuery('.countdown').text(remaining + ' characters remaining.');
}

jQuery(document).ready(function($) {
    updateCountdown();
    $('.short').change(updateCountdown);
    $('.short').keyup(updateCountdown);
});
</script>
<label>Short message <span class="countdown"></span></label>
<?php echo form_textarea('short_content', '', 'class="short"'); ?>

我使用了tinymce编辑器。它适用于我重新调整页面的时候。有人可以帮忙吗?

我的add.php文件看起来像这样:

<script type="text/javascript">
function updateCountdown(remaining_text) {
    // 140 is the max message length
    var remaining = 300 - remaining_text.length;
    jQuery('.countdown').text(remaining + ' characters remaining.');
}
</script>
                <label>short content <span class="countdown"></span></label>
                <?php echo form_textarea('short_content', '', 'class="short"'); ?>

我的tinymce init文件看起来像这样:

var short = $('textarea.short');
    if(short.length > 0) {
        short.tinymce({
            height: 150,
            language : 'lt',
            script_url : 'js/tiny_mce/tiny_mce.js',
            theme : 'advanced',
            skin : 'wp_theme',
            theme_advanced_toolbar_location : 'top',
            theme_advanced_toolbar_align : 'left',
            theme_advanced_resizing : true,
            plugins : "maxchars,autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist,wordcount",
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,link,unlink,anchor,|,bullist,numlist",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            theme_advanced_statusbar_location : "bottom",
            max_chars : 250,
max_chars_indicator : "lengthBox",
            toolbar: "wordcount",
              force_br_newlines : true,
        force_p_newlines : false,
             forced_root_block : false,

            file_browser_callback : "tinyBrowser",

            setup: function(ed){
                ed.onInit.add(function(ed) {
                  ed.pasteAsPlainText = true;
                });
                ed.onPaste.add(function(ed) {
                  ed.pasteAsPlainText = true;
                });

            },
                    });
    }
});

1 个答案:

答案 0 :(得分:0)

val()不会让你对tinymce的编辑有所了解。 tinyMCE.get('content id').getContent()会。此外,事件在tinymce api中指定。基于您的代码的tinymce初始化示例:

<script type="text/javascript">
    function updateCountdown(remaining_text) {
        // 140 is the max message length
        var remaining = 300 - remaining_text.length;
        jQuery('.countdown').text(remaining + ' characters remaining.');
    }

    var short = $('textarea.short');
    short.tinymce({
        height: 150,
        language : 'lt',
        script_url : 'js/tiny_mce/tiny_mce.js',
        theme : 'advanced',
        skin : 'wp_theme',
        theme_advanced_toolbar_location : 'top',
        theme_advanced_toolbar_align : 'left',
        theme_advanced_resizing : true,
        plugins : "maxchars,autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist,wordcount",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,link,unlink,anchor,|,bullist,numlist",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_statusbar_location : "bottom",
        max_chars : 250,
        max_chars_indicator : "lengthBox",
        toolbar: "wordcount",
        force_br_newlines : true,
        force_p_newlines : false,
        forced_root_block : false,

        file_browser_callback : "tinyBrowser",

        setup: function(ed){
            ed.onChange.add(function(ed, l) {
                if(l.content.length > 0) updateCountdown(l.content);              
            });
            ed.onKeyDown.add(function(ed, l) {
                if(ed.getContent().length > 0) updateCountdown(ed.getContent());              
            });             
            ed.onInit.add(function(ed) {
                ed.pasteAsPlainText = true;
            });
            ed.onPaste.add(function(ed) {
                ed.pasteAsPlainText = true;
            });         
        },
    });
});
</script>