首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将此js代码从内联更改为外部

将此js代码从内联更改为外部
EN

Stack Overflow用户
提问于 2013-06-21 17:30:15
回答 1查看 70关注 0票数 0

在对比了内联和外部javascript的良好实践之后,似乎外部脚本总是最好的,所以我有下面的代码:

代码语言:javascript
复制
$(function() {
    $('textarea').sceditor({
    charset: 'UTF-8',
    plugins: 'bbcode',
    width: "100%",
    autoExpand: true,
    toolbar: "bold,italic,underline,strike,quote|bulletlist|left,center,right|link,unlink|youtube,emoticon,image|pastetext|removeformat|maximize|source",
    style: "/includes/jscripts/sce/jquery.sceditor.default.min.css",
    enablePasteFiltering: true,
    // Emoticons list
    emoticons: {
    dropdown: {
    ":><:": "/includes/jscripts/sce/emoticons/angry.png",
    ":'(": "/includes/jscripts/sce/emoticons/cry.png",
    ":dizzy:": "/includes/jscripts/sce/emoticons/dizzy.png",
    ":D": "/includes/jscripts/sce/emoticons/grin.png",
    "^_^": "/includes/jscripts/sce/emoticons/happy.png",
    "<3": "/includes/jscripts/sce/emoticons/heart.png",
    ":huh:": "/includes/jscripts/sce/emoticons/huh.png",
    ":|": "/includes/jscripts/sce/emoticons/pouty.png",
    ":(": "/includes/jscripts/sce/emoticons/sad.png",
    ":O": "/includes/jscripts/sce/emoticons/shocked.png",
    ":sick:": "/includes/jscripts/sce/emoticons/sick.png",
    ":)": "/includes/jscripts/sce/emoticons/smile.png",
    ":P": "/includes/jscripts/sce/emoticons/tongue.png",
    ":S:": "/includes/jscripts/sce/emoticons/unsure.png",
    ":woot:": "/includes/jscripts/sce/emoticons/w00t.png",
    ":whistle:": "/includes/jscripts/sce/emoticons/whistle.png",
    ";)": "/includes/jscripts/sce/emoticons/wink.png",
    ":wub:": "/includes/jscripts/sce/emoticons/wub.png"
        }}
        }).change(function(e){
            var $this = $(this),
                $preview = $this.siblings('#preview');

        });
});

我如何才能使它在外部包含的文件中正常工作?这是与SCEditor一起使用的代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-21 17:31:42

只需将此内容复制到myjs.js等文件中,并使用以下命令将该文件包含在您的页面中

代码语言:javascript
复制
<script src="myjs.js"></script>

由于它使用的是jQuery,因此应该在包含jQuery之后包含此文件

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17231856

复制
相关文章

相似问题

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