【问题标题】:How to fix summernote is not a function?如何修复summernote不是函数?
【发布时间】:2021-11-02 00:34:22
【问题描述】:

我在将 Summernote 集成到我的代码时遇到问题,我一直遇到这个问题。我知道那里有很多答案,但我仍然找不到我的解决方案。

未捕获的类型错误:$(...).summernote 不是函数

当我将它包裹在 $(document).ready(function() { 中时,我的检查中出现了额外的错误:

jQuery.Deferred 异常:$(...).summernote 不是函数 TypeError: $(...).summernote 不是函数

当我点击检查中的错误行时,它会显示我的这一行代码

let msg = $("#summernote").summernote("code");

我已经在我的头脚本中声明了summernote cdn


<script type="text/javascript">

    $(document).ready(function() {
        $('#summernote').summernote({
            placeholder: 'description',
            tabsize: 2,
            height:200,
            toolbar:
            [
                ['style', ['style']],
                ['font', ['bold', 'underline', 'clear']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['table', ['table']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['help']]
            ]
        });    

    });
    

</script>

 <div class="nk-block nk-block-lg">
    <div id="summernote"></div>
 </div>

我该如何解决这个问题?

【问题讨论】:

    标签: javascript jquery summernote


    【解决方案1】:

    很可能该功能在页面加载时不可用(当它到达您的脚本时)。尝试将其包装在 $(document.ready(function() { /*your code here */ }); 中,以便在页面加载完所有资产(包括 Summernote)后运行它。

    【讨论】:

    • 我已经按照您的建议进行了包装,但仍然没有运气,当我将其包装在 document.ready jQuery.Deferred exception: $(...).summernote is not a function TypeError: $(...).summernote is not a function 时出现此错误
    • 这里:github.com/summernote/summernote/issues/2087 看起来 Summernote 的版本必须完全匹配 jquery。你验证了吗?
    • 我使用的是`jquery 3.4`和summernote 0.8.18
    【解决方案2】:

    找到我自己的答案。我必须将脚本声明到另一个文件中,这就是我解决自己问题的方法。

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2016-12-26
      • 2016-03-24
      • 2019-10-28
      • 2020-09-12
      • 2019-05-30
      • 2019-10-23
      • 2019-06-13
      • 2021-10-07
      相关资源
      最近更新 更多