为了减少工作,某些时候需要自动截取编辑器内容填充到简介表单中,在字段管理中,有一个“提交前运行js”文本框,在这里可以输入js脚本自动截取
添加自定义字段Introduction,在提交前运行js中输入下面代码即可。
v4.0.09版本后前端采用vue框架,代码如下:
if(vue.formData.Introduction.trim()=="") { var editorText=vue.formData.Content.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi,'').replace(/<[^>]+?>/g,'').replace(/\s+/g,' ').replace(/ /g,' ').replace(/>/g,' '); vue.formData.Introduction=editorText.left(180)+"..."; } return true;
v4.0.09之前版本采用jquery框架,代码如下:
var txt=UE.getEditor('Content').getContentTxt(); txt=txt.replace(/(^\s+)|(\s+$)/g, ""); txt=txt.replace(/\s/g,""); txt=txt.left(180)+"..."; if($("#Introduction").val()==""){ $("#Introduction").val(txt) } return true;