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

时间:2013-06-21 09:30:15

标签: 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一起使用。

1 个答案:

答案 0 :(得分:3)

只需将此内容复制到myjs.js等文件中,然后使用

将该文件包含在您的页面中
<script src="myjs.js"></script>

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