当我用本地文件控制台错误替换远程文件时 - Skulpt

时间:2016-08-26 19:11:02

标签: javascript html skulpt

我正在使用HTML和JavaScript编写Python编辑器,使用CodeMirror进行代码缩进,行编号和语法着色,以及执行Skulpt。

我有一些代码,其中引用了一个外部脚本(http://www.skulpt.org/static/skulpt.min.js):

<!DOCTYPE html>
<html>

<head>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript">
    </script>
    <script src="http://www.skulpt.org/static/skulpt.min.js" type="text/javascript">
    </script>
    <script src="skulpt-stdlib.js" type="text/javascript">
    </script>
    <script src="codemirror.js" type="text/javascript">
    </script>
    <script src="python.js" type="text/javascript">
    </script>
    <link href="codemirror.css" rel="stylesheet" type="text/css">
    <title></title>
</head>

<body>
    <script type="text/javascript">
        var editor;
        function outf(text) {
            var mypre = document.getElementById("dynamicframe");
            mypre.innerHTML = mypre.innerHTML + text;
        }

        function builtinRead(x) {
            if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
                throw "File not found: '" + x + "'";
            return Sk.builtinFiles["files"][x];
        }

        function runit() {
                var prog = editor.getDoc().getValue();
                var mypre = document.getElementById("dynamicframe");
                mypre.innerHTML = '';
                Sk.pre = "dynamicframe";
                Sk.configure({
                    output: outf,
                    read: builtinRead
                });
                (Sk.TurtleGraphics || (Sk.TurtleGraphics = {})).target = 'canvas';
                var myPromise = Sk.misceval.asyncToPromise(function() {
                    return Sk.importMainWithBody("<stdin>", false, prog, true);
                });
                myPromise.then(function(mod) {
                        console.log('success');
                    },
                    function(err) {
                        console.log(err.toString());
                    });
            }
            //<![CDATA[
        window.onload = function() {
                editor = CodeMirror.fromTextArea(document.getElementById('textbox'), {
                    mode: {
                        name: "python",
                        version: 2,
                        singleLineStringErrors: false
                    },
                    lineNumbers: true,
                    indentUnit: 4
                });
            } //]]>
    </script>
    <textarea id="textbox" name="textbox"></textarea>
    <br>
    <button onclick="runit()" type="button">Run</button>
    <pre id="dynamicframe"></pre>
    <div id="canvas"></div>
</body>

</html>

我希望本地存储所有脚本(不包括jQuery),因此我将http://www.skulpt.org/static/skulpt.min.js复制到本地服务器并将其称为skulpt.min.js。然后我换了一行:

<script src="http://www.skulpt.org/static/skulpt.min.js" type="text/javascript">
</script>

为...

<script src="skulpt.min.js" type="text/javascript">
</script>

现在代码在控制台中出现了这个错误:

Uncaught ReferenceError: Sk is not defined

在HTML第38行:

Sk.pre = "dynamicframe";

为什么会发生这种情况,我该如何解决?

0 个答案:

没有答案