【问题标题】:Field is empty when using NicEdit TextArea?使用 NicEdit TextArea 时字段为空?
【发布时间】:2018-01-25 03:00:51
【问题描述】:

我的网站上的模态表单上有以下 TextArea。一切正常,如果我在提交表单时将文本区域留空,则会显示错误。

<div class="lineEnter displayNone lineErroRefer"><label></label> <p class="errorField displayNone" id="summaryRefer">This field is required</p></div>
<div class="lineEnter">
    <label>What knowledge, skills or abilities can this person speak to on your behalf?</label>
    <textarea class="form-control" id="refer_summary" cols=30></textarea>
</div>

现在,我想格式化此文本区域中的文本,因此我正在使用 NicEdit,但我似乎无法使其正常工作。我已经更改了如下代码,但现在当我尝试提交表单时,始终显示 NicEdit 文本区域为空的错误,即使在文本区域中输入了值也是如此。

<script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script> 
<script type="text/javascript">
    //<![CDATA[
    bkLib.onDomLoaded(function() { 
        new nicEditor({buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript']}).panelInstance('refer_summary');
    });
    //]]>
</script>

NicEdit 文本区域显示正确,但我一定遗漏了什么……因为我现在无法提交表单!

感谢任何帮助!

编辑:

找到了答案,我只需要使用 NicEdit 的 content() 函数从文本中获取数据,而不仅仅是获取文本区域的值。以下对我有用:

var content = nicEditors.findEditor('refer_summary').getContent();

【问题讨论】:

    标签: javascript jquery html forms richtextbox


    【解决方案1】:

    您需要保存在 Nice edit div 中输入的文本,以更新您打算使用的实际文本编辑器(TextArea)。

    例如:

    nicEditors.findEditor(this.id).saveContent(); 
    

    这将迫使 niceeditor 将其潜水下的临时内容更新到它所配置的任何文本区域。

      $("textarea").each(function () {
                    nicEditors.findEditor(this.id).saveContent();
                });
    

    例如,对于每个按钮单击,您都希望将数据提交到服务器,

    你可以这样写一个 jquery 函数: 对于每个按钮单击,将 NiceEdit div 中的临时内容保存到相关的文本区域。

    $("button").click(function () {
                $("textarea").each(function () {
                    nicEditors.findEditor(this.id).saveContent();
                });
            });
    

    【讨论】:

      猜你喜欢
      • 2013-03-31
      • 2016-03-18
      • 1970-01-01
      • 2015-12-04
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 2015-08-15
      • 1970-01-01
      相关资源
      最近更新 更多