【问题标题】:Summernote: Manually open link dialogSummernote:手动打开链接对话框
【发布时间】:2019-08-30 19:52:06
【问题描述】:

我正在尝试编写一个脚本,当我单击按钮时会自动显示 Summernote 链接对话框。

例如,我有以下按钮:

<button class="btn btn-sm btn-info use_hyperlink" data-href="//files.examples.org.uk/song.mp3" type="button">Copy</button>

所以在我的 js 中我有:

$("#linklist").on("click", "button.use_hyperlink", function () {
    var href = $(this).data("href")
    modal = $("div.note-editor.note-frame.panel.panel-default div.modal.link-dialog")
    modal.addClass("in").modal("show")
    modal.find("input.note-link-url.form-control.note-form-control.note-input").val(href)
    modal.find("button.note-btn.note-btn-primary.note-link-btn").prop("disabled", false).removeClass("disabled").attr("type","button")
})  

打开对话框,成功粘贴href,但点击Insert Link按钮提交summernote所在的表单。

查看6765 线上的summernote code 有一个名为showLinkDialog 的函数,我想它就是我想要的。但是当我尝试时:

$(document).ready(function () {
    $("textarea#summernote").summernote({height: 500});
    $("#linklist").on("click", "button.use_hyperlink", function () {
        var href = $(this).data("href")
        $("textarea#summernote").showLinkDialog({
            url: href
        });
    })  
})

我收到了Uncaught TypeError: $(...).showLinkDialog is not a function

【问题讨论】:

    标签: javascript jquery summernote


    【解决方案1】:

    尝试触发点击按钮

    $('.note-insert [aria-label^="Link"').trigger('click')
    

    【讨论】:

      猜你喜欢
      • 2011-01-03
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 2012-07-16
      相关资源
      最近更新 更多