我需要在WordPress中编写新帖子时限制摘录字段的长度。当达到字符或单词的限制时,我想显示错误消息并阻止用户写更多输入。
我发现了一些提示,但实际的Wordpress版本没有。我应该从哪里开始调查,是否有过滤器来输出自定义摘录字段?
答案 0 :(得分:0)
在tinymce Script中使用此代码在Them按钮下。
和“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(/ /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;
}
}
});
}!