首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ajax提交nicEdit

Ajax提交nicEdit
EN

Stack Overflow用户
提问于 2014-03-13 14:41:46
回答 2查看 1.2K关注 0票数 1

我正在我的一个项目中使用nicEditor,我想使用插件中的jQuery提交内容。以下是我的代码

代码语言:javascript
复制
<script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor().panelInstance('txt1');
});
</script>


<script>
$(document).ready(function()
{
    $('#submit-from').on('submit', function(e)
    {
        e.preventDefault();
        $('#submit').attr('disabled', ''); // disable upload button
        //show uploading message

        $(this).ajaxSubmit({
        target: '#output-login',
        success:  afterSuccess //call function after success
        });
    });
});

function afterSuccess()
{
    $('#submit-from').resetForm();  // reset form
    $('#submit').removeAttr('disabled'); //enable submit button
    $('#loadding').html('');
}
</script>


<form id="submit-from" action="submit.php" method="post">

<input type="text" id="title" name="title" />

<textarea id="txt1" name="txt1" ></textarea>

<input type="submit" id="submit" value="Submit"/></div>

</form>

我正在使用

来自插件的jQuery:http://malsup.com/jquery/form/

nicEdit:http://nicedit.com/

所有的工作都很好,除了nicEdit中似乎没有发布的内容。如果删除nicEdit文本区,则可以正常开机自检。有人能给我指出问题所在吗?真的很适合你的帮助。

EN

回答 2

Stack Overflow用户

发布于 2014-06-27 19:46:59

试试这个:

代码语言:javascript
复制
// Get values from NICEditors
$('textarea').each(function () {
    var id_nic = $(this).attr('id');
    var nic = nicEditors.findEditor(id_nic);
    if (nic) nic.saveContent();
});             
票数 2
EN

Stack Overflow用户

发布于 2014-03-13 15:37:34

我认为您应该对nicEdit的可内容编辑div的HTML进行编码,然后在尝试提交表单时将该值传递给文本区域。

代码语言:javascript
复制
$(document).ready(function()
{
    $('#submit-from').on('submit', function(e)
    {
        e.preventDefault();
        $('#submit').attr('disabled', ''); // disable upload button
        //show uploading message


        var encodedHTML = String($('.nicEdit-main').html())
                .replace(/&/g, '&amp;')
                .replace(/"/g, '&quot;')
                .replace(/'/g, '&#39;')
                .replace(/</g, '&lt;')
                .replace(/>/g, '&gt;');

        $('#txt1').val(encodedHTML);

        $(this).ajaxSubmit({
            target: '#output-login',
            success:  afterSuccess //call function after success
        });
    });
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22370993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档