1.ueditor结合validate验证
<script type="text/javascript" charset="utf-8" src="${ctxStatic}/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctxStatic}/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="${ctxStatic}/ueditor/lang/zh-cn/zh-cn.js"></script>
<textarea id="inputTextarea" name="noticeDescription" style="width:85%;height:330px;"></textarea>
<textarea class="input-user" id="contentid" style="display: none;" name="content"></textarea>
<textarea class="input-user" id="contentnolabel" style="display: none;" name="contentnolabel"></textarea>
<script type="text/javascript">
$(function(){
//先删除掉以前的ueditor,否则第二次打开的时候会渲染失败
UE.getEditor('inputTextarea');
//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用 UE.getEditor('editor')就能拿到相关的实例
var ue = UE.getEditor('inputTextarea', {
toolbars: [
['justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
'bold','italic', 'underline', 'removeformat', 'formatmatch', 'autotypeset', 'indent','|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
'simpleupload', 'emotion','|',
'horizontal', 'date', 'time', 'spechars', 'snapscreen','|',
'inserttable', 'deletetable', 'charts', '|','source', 'undo', 'redo','|',
'print', 'preview', 'drafts']
],
elementPathEnabled : false, //元素路径
maximumWords:2000, //最大字符数
autoHeightEnabled: false //滚动条
});
var validator = $("#noticeForm").submit(function() {
ue.sync();
}).validate({
submitHandler:function(form){
$(".btn-confirm").attr("disabled",true);
$("#contentid").val(UE.getEditor('inputTextarea').getContent());
var keyCon = UE.getEditor('inputTextarea').getContentTxt();
if(keyCon!="")
{
var keyConNew = keyCon.substring(0,20);
}
else{
var keyConNew = "【图片】";
}
$("#contentnolabel").val(keyConNew);
document.setweb.content.value=UE.getEditor('inputTextarea').getContent()
form.submit();
},
wrapper: "div",
ignore: "",
rules: {
title: { //name
required: true,
imTag: true,
maxlength:30
},
noticeDescription: { //name
required: true
}
},
messages: {
title: { //name
required: "主题不可为空",
maxlength: "主题不可超出30个字符"
},
noticeDescription: { //name
required: "内容不可为空",
maxlength: "内容不能超过2000个字符"
}
}
});
validator.focusInvalid = function() {
if( this.settings.focusInvalid ) {
try {
var toFocus = $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []);
if (toFocus.is("textarea")) {
UE.getEditor('inputTextarea').focus();
} else {
toFocus.filter(":visible").focus();
}
} catch(e) {
}
}
};
ue.ready(function(){
//编辑时写入
var con = "${notice.content}";
ue.setContent(con);
});
$(".main-min-height").css("min-height",jQuery(document).height() - 55);
});
</script>