【问题标题】:Summernote insert quoteSummernote 插入报价单
【发布时间】:2016-05-25 03:02:50
【问题描述】:

我正在使用 Summernote 所见即所得的编辑器,我需要插入引号。 在文档中我没有找到如何插入这样的东西的方法,我尝试使用 insertNode,但它返回 Uncaught TypeError: Cannot read property 'toUpperCase' of undefined 我发现 insertNode 仅适用于空文档.createElement。

我已经尝试过使用 summernote('code', quote);也是,但它只是替换内容。我什至尝试创建新元素、添加类和添加内容,但仍然遇到相同的 toUpperCase 错误。

这是我已经尝试过的。

function quote(post) {
    var entry   =   $(post),
        author  =   entry.find('.quotable-author').text(),
        date    =   entry.find('.quotable-date').text(),
        content =   entry.find('.quotable-content').html(),
        quote   =   '<blockquote class="quote">' + content + '<footer>' + author + ' - ' + date + '</footer></blockquote>';

    $('.editor').summernote('insertNode', quote);
}

这可以在summernote中完成还是我应该搜索另一个所见即所得的编辑器?

【问题讨论】:

    标签: javascript quote summernote


    【解决方案1】:

    insertNode 将第一个参数作为元素而不是字符串。您可以使用 jquery 轻松创建元素。

    var quote = $('<blockquote class="quote">hello<footer>world</footer></blockquote>')[0];
    $('.editor').summernote('insertNode', quote);
    

    http://summernote.org/deep-dive/#insertnode

    【讨论】:

    • 谢谢,这项工作,但为什么它返回 Uncaught TypeError: quote is not a function on next time I want to use that function on the same editor in the same page?
    • 我不明白你的回答。请详细说明。
    • 我正在使用该函数 quote 将引用的帖子添加到编辑器中,就像这样 quote me 在第一次插入时它就像魅力一样,但在接下来或者其他它只是返回引号不是一个函数。
    猜你喜欢
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 2014-08-14
    • 2017-09-14
    • 1970-01-01
    • 2018-04-29
    • 2018-01-07
    • 1970-01-01
    相关资源
    最近更新 更多