错误:使用本地文件时,summernote不是功能 [英] Error: summernote is not a function when using local files
问题描述
我遇到了一个很奇怪的问题.当我使用本地的summernote文件加载文本编辑器时,发生了".summernote不是函数".但是,如果我使用CDN文件加载编辑器,则一切正常.这是我的HTML标头代码:
I am having a really odd problem. When I used my local summernote files to load the text editor, ".summernote is not a function" happened. However, if I used the cdn files to load the editor, everything went fine. Here is my HTML header code:
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="UTF-8"/>
<title><?php echo $title; ?></title>
<base href="<?php echo $base; ?>"/>
<?php if ($description) { ?>
<meta name="description" content="<?php echo $description; ?>"/>
<?php } ?>
<?php if ($keywords) { ?>
<meta name="keywords" content="<?php echo $keywords; ?>"/>
<?php } ?>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>
<link href="favicon.ico" rel="icon">
<!-- include jquery -->
<script type="text/javascript" src="javascript/jquery/jquery-2.1.1.min.js"></script>
<!-- include libraries BS3 -->
<script type="text/javascript" src="javascript/bootstrap/js/bootstrap.min.js"></script>
<link href="stylesheet/bootstrap.css" type="text/css" rel="stylesheet"/>
<!-- include font-awesome-->
<link href="javascript/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet"/>
<!-- include datetimepicker-->
<script src="javascript/jquery/datetimepicker/moment.js" type="text/javascript"></script>
<script src="javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<link href="javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet" media="screen"/>
<!-- include customer stylesheet-->
<link type="text/css" href="stylesheet/stylesheet.css" rel="stylesheet" media="screen"/>
<!--include customer js-->
<script src="javascript/common.js" type="text/javascript"></script>
<?php if ($styles) { ;?>
<?php foreach ($styles as $style) { ;?>
<link href="<?php echo $style;?>" rel="stylesheet"></link>
<?php } ;?>
<?php } ;?>
<?php if ($scripts) { ;?>
<?php foreach ($scripts as $script) { ;?>
<script href="<?php echo $script;?>" type="text/javascript"></script>
<?php } ;?>
<?php } ;?>
<!-- <link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">-->
<!-- <script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script>-->
我试图直接加载本地文件,而不是通过PHP回显它们,但是问题仍然存在.
I tried to load the local files directly instead of echo them by PHP, but the problem is still there.
我检查了每个href,没有无效链接.
I checked every href, there is no dead link.
然后,我在javascript文件夹下创建了一个名为 test.html
的纯HTML文件,并且使用本地文件很好地加载了文本编辑器.
Then I created a pure HTML called test.html
file underneath the javascript folder, and the text editor loaded fine by using local files.
通过我使用的框架的方式是CI,文件结构是:
By the way the framework I'm using is CI, and the file structure is:
root
├──javascript
├──bootstrap
├──jquery
├──summernote
├──font-awesome
├──test.html
推荐答案
我认为您没有以正确的顺序包含脚本.
I don't think you're including your scripts in the right order.
从CDN加载后,您的订单如下所示:
When you loaded from the CDN, your order looked something like this:
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script>
<script src="javascript/common.js" type="text/javascript"></script>
...这是合乎逻辑的,因为您要确保在执行主要JS代码时已加载 summernote
.
. . . which is logical, because you want to be sure that summernote
is loaded by the time your main JS code executes.
但是,您的PHP依赖关系管理代码在同一脚本之后注入了链接到本地文件的标签.基本上,也要在客户脚本之前转储所有这些逻辑:
However, your PHP dependency management code was injecting the tags linking to local files after that same script. Basically, dump all of that logic before your customer's script too:
<?php if ($styles) { ;?>
<?php foreach ($styles as $style) { ;?>
<link href="<?php echo $style;?>" rel="stylesheet"></link>
<?php } ;?>
<?php } ;?>
<?php if ($scripts) { ;?>
<?php foreach ($scripts as $script) { ;?>
<script src="<?php echo $script;?>" type="text/javascript"></script>
<?php } ;?>
<?php } ;?>
<script src="javascript/common.js" type="text/javascript"></script>
(还要注意,在您的PHP中,您为脚本标记的生成编写了 href
而不是 src
.)
(Also note that in your PHP you wrote href
instead of src
for your script tag generation.)
这篇关于错误:使用本地文件时,summernote不是功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!