zoukankan      html  css  js  c++  java
  • 当使用ckeditor控件时,需要校验输入内容是否为空的一种解决

    fckeditor 验证内容是否为空 fckeditor Js验证表单 原来的代码代码如下

      <script language = "javascript">  <!--  function checkForm(){  if (document.form1.content.value==""){  alert("请输入内容!");  return false;  }  return true;  }  //-->  </script>  <form name="form1" method="post" action="" onsubmit="return checkForm();">  <FCK:editor id="content" basePath="fckeditor/" height="350" >  </FCK:editor>  <input type="submit" name="Submit" value="发布">  </form> 

    这样是我们写程序中最经常的写法 提交之前进行验证内容是否为空! 使用了编辑器以后 在第一次按提交按钮的时候 总是获取不到编辑器的值 内容已经输入 可是content并没有任何值!需要我们再次点提交按钮 content 才能获取到值! 对于这个问题 好多人都觉得困惑!有写是用JS去读取输入域中的HTML内容!可是这只对全JS版本的fckeditor 才有效果 对 JSP版本的 并不起作用!对于这样的状态 也只能怪fckeditor开发者了!而代码太多太麻烦 想要修改其核心谈何容易! 本人经过不断的测试 现得到一个方法可以解决次问题!先拿出来大家分享 改写代码如下

      <script language = "javascript">  <!--  function checkForm(){  setTimeout("SendForm()",50);  return false;  }  function SendForm(){  if (document.form1.content.value==""){  alert("请输入内容!");  return;  }  document.form1.submit();  }  //-->  </script>  <form name="form1" method="post" action="" onsubmit="return checkForm();">  <FCK:editor id="content" basePath="fckeditor/" height="350" >  </FCK:editor>  <input type="submit" name="Submit" value="发布">  </form> 

    修改成这样的目的是因为编辑器已经监视了onsubmit这个事件 是要在提交以后才把跟新的内容置入隐藏域content 中,原先的来不及置入内容便已经执行了验证事件所以当然取不到及时的内容!
    //==============================================
    以上内容为转帖,不过经过我实际工作的检验,有效。

  • 相关阅读:
    html5 canvas 渐变
    html5 canvas 画直线
    html5在canvas中插入图片
    Window文件夹右击菜单定制
    HTML中解决双击会选中文本的问题
    Linux 下修改mysql 字符集编码
    mysqlimport导入命令使用
    PAM 2500 荧光数据导出数据整合脚本
    Resources for Ecology and Evolution
    Plant Ecology Journal Club, 分享主题和文献列表 825, 2019年春
  • 原文地址:https://www.cnblogs.com/guanghuiqq/p/2628650.html
Copyright © 2011-2022 走看看