与ckeditor集成的textarea的jquery验证

前端之家收集整理的这篇文章主要介绍了与ckeditor集成的textarea的jquery验证前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个文本区域
  1. <td><textarea id="event-body" name="body">
  2. <p class="error"></p>

这与CKEDITOR整合在一起

  1. CKEDITOR.replace("event-body")

并且jquery验证plugin.代码是这样的

  1. $('#event').validate({
  2. rules:{
  3. name:{
  4. required: true
  5. },},messages:{
  6. body:{
  7. required: "event body is required"
  8. }
  9. },errorPlacement: function(error,element){
  10. $(element).each(function (){
  11. $(this).parent('td').find('p.error').html(error);
  12. })
  13. });

代码工作得很好但是当我输入我的textarea元素时,我仍然会收到错误消息,直到我单击它两次.即我必须提交我的页面两次,以便即使textarea不为空也不会出现错误消息.

有没有办法顺利验证它(无需点击两次).

解决方法

看看 here

基本上你需要打电话

  1. CKEDITOR.instances.editor1.updateElement();

在运行验证之前.

只需将editor1替换为textarea的名称即可.

然后打电话

  1. $(myformelement).validate();

编辑

  1. $("#my-form-submit-button").click(function(e){
  2. e.preventDefault();
  3. CKEDITOR.instances.event-body.updateElement();
  4. $('#event').validate({
  5. ...options as above..
  6. });o
  7. })

猜你在找的jQuery相关文章