在jQuery Validate总是验证不通过,原因就是在 CKEditor 编辑器填写了内容之后,编辑器并不是立即把内容更新到原来的 textarea 元素中的
可以在提交表单之前进行如下修改
CKEDITOR.instances.content.updateElement();
html标签为:
<textarea class="ckeditor" name="content" rows="4" cols="30"></textarea>
完整html代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="${contextPath}/scripts/validate/jquery.validate.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="${contextPath}/scripts/jquery-1.4.4.js"></script>
<script type="text/javascript" src="${contextPath}/scripts/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="${contextPath}/scripts/validate/jquery.validate.js"></script>
<script>
var valdater;
jQuery(document).ready(function(){
valdater=jQuery("#form").validate({
errorPlacement: function(error, element) {
error.appendTo( element.siblings("span"));
},
meta:"validate",
rules:{
content:{
required: true
}
},
messages:{
content:{required:'<s:text name="label.input.message_cn_content" />'} }
});
});
function doSubmit(){
CKEDITOR.instances.content.updateElement();
if(valdater.form()){
document.notice_form.submit();
return true;
}
return false;
}
</script>
</head>
<body id="fbody">
<div id="iframe_warp">
<form name="notice_form" id="form" action="${contextPath}/operator/message_add.action" method="post">
<textarea class="ckeditor" name="content" rows="4" cols="30"></textarea</s:form>
<input type="button" class="s_button" onclick="return doSubmit();" value="<s:text name="label.submit" />"></input>
</form>
</body>
</html>