在用WordPress编写新文章时,我需要限制摘录字段的长度。当达到字符或单词的限制时,我想显示一条错误消息,并阻止用户编写更多的输入。
我找到了一些提示,但没有实际的Wordpress版本。我应该从哪里开始调查,是否有一个过滤器来输出自定义的摘录字段?
发布于 2014-04-19 10:21:56
在tinymce脚本中使用它们下面的代码Button。
“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;
}
}
});
}!
https://stackoverflow.com/questions/23168696
复制相似问题