<script id="addarticle" name="content" type="text/plain">请输入文章内容...</script>
//富文本编辑器文件配置
var options={
serverUrl:baseUrl + 'core/upload/ueditor?type=200&schid=' +JSON.parse(sessionStorage.getItem("userMsg")).schid,
toolbars: [['fullscreen','source', 'indent','anchor','autotypeset','fontfamily', 'fontsize','lineheight','|','forecolor','backcolor','|', 'italic', 'bold', 'underline','formatmatch','|', 'justifyleft','justifycenter', 'justifyright','justifyjustify','|','undo','redo','|','time','date','|','insertorderedlist', 'insertunorderedlist','|','insertimage', 'link', 'unlink','music','insertvideo','|','preview','cleardoc','removeformat','help']],
autoHeightEnabled: false,
autoFloatEnabled: false,
autoClearinitialContent: true,
initialFrameWidth: 1000,
initialFrameHeight: 400,
elementPathEnabled : false ,
wordCount:false,
BaseUrl: '',
zIndex: '100'
};
var addindex = UE.getEditor('addarticle', options);//创建一个编辑器
var layeditContent = addindex.getContent();
我发现使用
console.log(layeditContent )
console.log(layeditContent =="")
console.log(layeditContent ==" ")
打印出来的竟然是
真的是搞不明白为什么输出的空。最后判断是空不对。判断是空格也不对啊。
最后终于发现了下面的方式可以判断的。
var layeditContent =addindex.getPlainTxt();//获取带格式的纯文本.
if(layeditContent == "请输入文章内容...\n"||layeditContent == "\n"){ //这里麻烦一点使用两个判断条件
alert("请输入文章内容");
}
我就使用了getPlainTxt()。这个保留段落格式。编辑器默认的最外层是有个p标签的。所以在最后转化的时候会有个/n
所以判断的时候就可以根据是layeditContent == "\n"知道他是空值了。
但是我们最后提交后台的编辑器的内容必须用getContent()这个函数。是编辑器里html的所有的内容的。
使用getPlainTxt可能会把有序列表这些序号都筛选掉