在实现ckeditor之后必须进行哪些更改

时间:2014-03-27 11:52:42

标签: javascript html

理念:

我正在使用CKEditor在我的网站论坛上发帖。

问题:

当我在post_body textarea中输入问题并点击创建主题时,会发生以下情况: -

  • 首先,会弹出一个警告框,说明"请输入内容 body"(请注意,身体textarea不为空)

  • 然后立即重定向到主题。(请注意,正文中已发布的内容已插入数据库表中)

我不希望弹出警报框。我该怎么办?

代码:

<div id="middlePanel">
    <table style="background-color:#FFF; border:#069 1px solid; border-top:none;" width="100%" border="0" align="center" cellpadding="12" cellspacing="0">
      <tr>
        <td width="80%" valign="top">
          <h2><?php echo $forum_section_title; ?></h2>
          <div id="breadcrumbs"><a href="forumhome.php">Forum</a>&larr;<a href="sections.php?id=<?php echo $forum_section_id; ?>"><?php echo $forum_section_title; ?></a></div><br /><br />
          <h2>Creating New Topic In the  <em><?php echo $forum_section_title; ?></em>&nbsp; Forum</h2>
          <form action="php_parsers/forumpost_system.php" method="post" name="form1" id="form1">
            <input name="post_type" type="hidden" value="a" />
            Topic Author:<br /><input name="topic_author" type="text" disabled="disabled" maxlength="64" style="width:96%;" value="<?php echo $log_username; ?>" />
            <br /><br />
            Please type in a title for your topic here:<br /><input name="post_title" type="text" maxlength="64" style="width:96%;" /><br /><br />
            Please type in your topic body:<br />
            <textarea name="post_body" id="post_body" rows="15" style="width:96%;"></textarea>
            <script>
            CKEDITOR.replace( 'post_body' );
            </script>
            <!--<iframe name="richTextField" id="richTextField" style="border:#000000 1px solid; width:700px; height:300px;"></iframe>-->
            <br /><br />
            <input name="" type="submit" value="Create my topic now!" onclick="validateMyForm();"/>
            <input name="fsid" type="hidden" value="<?php echo $forum_section_id; ?>"/>
            <input name="fstitle" type="hidden" value="<?php echo $forum_section_title; ?>"/>
            <input name="uid" type="hidden" value="<?php echo $log_id; ?>"/>
            <input name="uname" type="hidden" value="<?php echo $log_username; ?>"/>
            <input name="upass" type="hidden" value="<?php echo $log_password; ?>"/>
          </form>
        </td>
        <td width="20%" valign="top">&nbsp;</td>
      </tr>
  </table>
  </div>

这些是我头标记中的javascript函数

<script> 
function validateMyForm ( ) 
{ 
    var isValid = true;
    if ( document.form1.post_title.value == "" ) 
    { 
        alert ( "Please type in a title for this topic" ); 
        isValid = false;
    } 
    else if ( document.form1.post_title.value.length < 10 ) 
    { 
        alert ( "Your title must be at least 10 characters long" ); 
        isValid = false;
    } 
    else if ( document.form1.post_body.value == "" ) 
    { 
        alert ( "Please type in your topic body." ); 
        isValid = false;
    }
    return isValid;
}

如果我没有使用CKEditor,那么一切正常。但如果我使用它,我就会遇到上述问题。我认为我必须做一些我不知道的改变。所以在那里使用CKEditors的人,请帮助我。

1 个答案:

答案 0 :(得分:0)

您并未告诉CKEditor更新原始<textarea>元素。

当您使用CKEditor时,编辑器将使用<textarea>的内容来填充自己 - 当您提交表单时,编辑器将使用编辑器的编辑内容自动更新<textarea>

您需要做的是在检查该元素的内容之前强制它提前更新元素。

因此,在测试document.form1.post_body.value之前,请尝试运行以下代码...

CKEDITOR.instances.post_body.updateElement();
相关问题