php - nicEdit 文本区域的默认值

标签 php textarea nicedit

代码如下

<?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 textarea 输入任何文本,它会显示 length=4。 为什么会这样? nicedit textarea 有默认值吗?如果是,如何更改?

最佳答案

通过注释 3 行解决问题。在 niceEdit.js 中搜索以下代码。默认情况下,它包含一个 <br /> .

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

关于php - nicEdit 文本区域的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15896157/

相关文章:

php - 将关联数组存储到 MySQL 并在 PHP 中检索它的方法?

php - 使用 Visual Studio 2008 在 Windows 上编译我自己的 PHP 扩展

javascript - Tinymce 自动调整大小问题

php - php中如何保存文本区域的数据

javafx - 如何在 JavaFx textArea 中附加多色文本

javascript - 如何设置niceedit不可编辑

knockout.js - 将 NicEdit 与 Knockout 一起使用

php - 向 PHP 构造函数发送接口(interface)

php - 调整 png/jpeg 图像的大小

javascript - NicEdit 干扰 JQuery $ 别名