Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 剩余字符数_Javascript_Php_Tinymce - Fatal编程技术网

Javascript 剩余字符数

Javascript 剩余字符数,javascript,php,tinymce,Javascript,Php,Tinymce,我试着把剩下的字符放在文本区域。但它不起作用。我的剧本: <script type="text/javascript"> function updateCountdown() { // 140 is the max message length var remaining = 300 - jQuery('.short').val().length; jQuery('.countdown').text(remaining + ' characters remai

我试着把剩下的字符放在文本区域。但它不起作用。我的剧本:

<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"'); ?>
val()
无法获取tinymce编辑器的值。
tinyMCE.get('content id')。getContent()
will。此外,事件在中指定。基于您的代码的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>

函数updateCountdown(剩余的\u文本){
//140是最大消息长度
var剩余=300-剩余文本长度;
jQuery('.countdown').text(剩余+剩余字符');
}
var short=$('textarea.short');
短文({
身高:150,
语言:'lt',
脚本url:'js/tiny\u mce/tiny\u mce.js',
主题:"先进",,
皮肤:“wp_主题”,
主题\高级\工具栏\位置:'顶部',
主题\u高级\u工具栏\u对齐:“左”,
主题\u高级\u大小调整:正确,
插件:“maxchars、autolink、List、pagebreak、style、layer、table、save、advhr、advimage、advlink、情感、iSpell、inlinepopups、insertdatetime、preview、media、searchreplace、print、contextmenu、paste、directionality、fullscreen、noneditable、visualchars、NoBreaking、xhtmlxtras、template、advlist、wordcount”,
主题高级按钮1:“粗体、斜体、下划线、删除线、|、链接、取消链接、锚定、|、金条、纽姆利斯特”,
主题\高级\按钮2:“”,
主题\高级\按钮3:“”,
主题\高级\状态栏\位置:“底部”,
最大字符数:250,
最大字符指示器:“长度框”,
工具栏:“字数”,
force\u br\u新词:对,
force_p_新行:false,
强制根块:false,
文件\浏览器\回调:“tinyBrowser”,
设置:功能(ed){
ed.onChange.add(函数(ed,l){
如果(l.content.length>0)updateCountdown(l.content);
});
ed.onKeyDown.add(函数(ed,l){
如果(ed.getContent().length>0)updateCountdown(ed.getContent());
});             
ed.onInit.add(功能(ed){
ed.pasteAsPlainText=true;
});
ed.onPaste.add(函数(ed){
ed.pasteAsPlainText=true;
});         
},
});
});

。肯定有别的事发生了。是的,我知道,但我重新翻页时它就起作用了。也许这是一个小问题:关注?发布,没有测试它,但应该可以。我尝试了,但它不起作用。我编辑了我的第一篇文章,请查看!谢谢你的回复,仅供参考。它在刷新后工作,因为您将在textarea中获得信息-您无法使用标准jquery事件在tinymce中获取动态信息。另外,一点绿色的“接受”字样作为感谢信也不错!祝你有愉快的一天!
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;
                });

            },
                    });
    }
});
<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>