【问题标题】:NicEdit doesn't save textarea when form submitted through javascript href通过 javascript href 提交表单时,NicEdit 不保存 textarea
【发布时间】:2014-03-12 09:55:54
【问题描述】:

http://www.netshinesoftware.com/index.php?cID=128&bID=102讨论了通过javascript提交表单时NicEdit不会保存textareas内容的问题,但解决方案

for(var i=0;i<editor1.nicInstances.length;i++){editor1.nicInstances[i].saveContent();}

editor1.addEvent('blur', function() { this.nicInstances[0].saveContent(); });

当编辑器由此创建时不起作用:

bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });

任何想法为什么?所有解决方案(欢迎使用 jquery 等)

【问题讨论】:

    标签: javascript forms form-submit nicedit


    【解决方案1】:

    我也遇到过同样的问题,但这对我有用。

    function submitForm()
    {
        var data = new Object();
        var nicE = new nicEditors.findEditor('text');
        var html = nicE.getContent().replace(/\"/ig,'"');
    
        data["projectid"] = $('select#projects option:selected').val();
        data["type"] = $('select#type option:selected').val();
        data["taskid"] = $('select#taskid option:selected').val();
        data["tasktype"] = $('select#tasktype option:selected').val();
        data["title"] = $('input#title').val().replace(/\"/ig,'"');
        data["text"] = html; 
    
        xajax_task_action('save_importtask',data);
    }
    

    如果您有多个 nicEdit 实例,则使用迭代并将内容保存在数组中。 我希望它能帮助您找到解决问题的方法。

    【讨论】:

    • 感谢您的帮助。它一直显示“TypeError:nicE.getContent 不是函数”,只是不知道为什么。哦,也许我应该提一下,我现在每次点击都会调用这段代码来测试......不仅仅是在提交时。
    • 好吧,这只是一种解决方法,但这有助于我保存我的 textarea 的内容(它既没有 id 也没有 class,而且我通常每页只有一个 textarea)。每次用户单击某处时,我都会设置 POST-Var ......不是很好,但在这里对我有用。 $(document).click(function() { if($('#contentRight').find('.nicEdit-main').text()){ var myText = $('#contentRight').find('.nicEdit-main').text(); var input = $("<input>") .attr("type", "hidden") .attr("name", "text").val(myText); $('#formular').append($(input)); } });
    猜你喜欢
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    • 2011-10-14
    相关资源
    最近更新 更多