【问题标题】:How to restrict text length of a extract in WordPress editor?如何在 WordPress 编辑器中限制提取的文本长度?
【发布时间】:2014-04-19 18:21:56
【问题描述】:

在 WordPress 中撰写新文章时,我需要限制摘录字段的长度。当达到字符或单词的限制时,我想显示一条错误消息并阻止用户编写更多输入。

我发现了一些提示,但在实际的 Wordpress 版本中一无所获。我应该从哪里开始调查,是否有过滤器可以输出自定义摘录字段?

【问题讨论】:

    标签: wordpress filter


    【解决方案1】:

    在 tinymce 脚本中使用“在他们按钮下的代码”。

    而“id_txt”是你的文本区id

    setup : function(ed) {
    ed.onKeyUp.add(function(ed, e) {
    txt = tinyMCE.activeEditor.getContent();
    
    var strip = (tinyMCE.activeEditor.getContent()).replace(/(<([^>]+)>)/ig,””);
    var text =  strip.length + ” Characters”
    tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + ‘_path_row’), text);
    
    id_txt = tinyMCE.activeEditor.id;
    //alert (id_txt);
    //strip the html
    txt = txt.replace(/(<([^>]+)>)/ig,””);
    txt = txt.replace(/&nbsp;/g,””);
    if (id_txt == ‘blog_content’)
    {
    
    if (txt.length > 1000)
    {
    $(“#ErrorMsg”).css(‘display’,’block’);
    $(“#ErrorMsg”).html(‘Please Enter Only 1000 Charecters !’);
    txt = txt.substring(0,1000);
    text =  1000 + ” Characters”;
    tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + ‘_path_row’), text);
    tinyMCE.activeEditor.setContent(txt);
    ed.selection.select(ed.getBody(), true);
    ed.selection.collapse(false);
    return false;
    }
    }
    
    /// Condition for Header Qutes
    
    if (id_txt == ‘header_content’)
    {
    if (txt.length > 150)
    {
    $(“#ErrorMsg”).css(‘display’,’block’);
    $(“#ErrorMsg”).html(‘Please Enter Only 150 Charecters !’);
    txt = txt.substring(0,150);
    text =  150 + ” Characters”;
    tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + ‘_path_row’), text);
    tinyMCE.activeEditor.setContent(txt);
    ed.selection.select(ed.getBody(), true);
    ed.selection.collapse(false);
    return false;
    }
    }
    
    });
    }!
    

    【讨论】:

      猜你喜欢
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 2017-07-01
      • 2015-04-07
      • 2015-10-30
      相关资源
      最近更新 更多