nicEdit文本区域的默认值

4

这里有一段代码

<?php 
if (isset($_POST['flag'])) {

    $length=strlen(trim($_POST['area']));
     echo "Length of abstract  :  ".$length;
     if (!strlen(trim($_POST['area']))){
        $abstractErrorMsg = "Please enter the abstract of your article";
        echo $abstractErrorMsg;
    }
}
?>
<form method="post" action="">
        <input type="hidden" name="flag" value="hidden">
        <script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script> 
        <script type="text/javascript">
                            //<![CDATA[
                            bkLib.onDomLoaded(function() {
                                nicEditors.editors.push(
                                        new nicEditor().panelInstance(
                                        document.getElementById('myNicEditor')
                                        )
                                        );
                            });
                            //]]>
                        </script>

                        * Abstract

                                <textarea name="area" id="myNicEditor" style="width: 300px;height: 100px;"></textarea>

        <input type="submit" name="btn">
    </form>

如果我在没有输入任何文本的情况下提交表单到 nicedit 文本区域,它会显示长度为4。 为什么会这样?是否有 nicedit 文本区域的默认值?如果有,如何更改?


这是真正的代码吗?我会假设您在textarea标记之间有一些空格字符... - CBroe
没有单个空格符号在标签之间。这是原始代码。 - Nirali Joshi
1个回答

4

通过注释掉这3行代码解决问题。在niceEdit.js中查找以下代码,它默认包含一个<br />标签。

init : function() {
            this.elm.setAttribute('contentEditable','true');    
            //if(this.getContent() == "") {
            //  this.setContent('<br />');
            //}
            this.instanceDoc = document.defaultView;

我正在使用 nicEdit-latest.js。 - Nirali Joshi
我从今天从他们的网站下载的niceEdit.js文件的开发者版本中获取了答案中的代码。(版本0.9 r24于2012年6月7日发布) - Rajeesh V
使用 nicEdit.js 时,文本区域没有加载所有功能。它只加载了字体、格式和字号。我想要全部功能。 - Nirali Joshi
我从这里http://nicedit.com/download.php下载了完整版本。还有其他版本吗? - Rajeesh V
我也可以在http://nicedit.com/demos.php中使用所有的功能。那就是你需要的全部吗? - Rajeesh V

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接