运行应用程序时出现javascript错误

时间:2017-03-01 07:30:44

标签: javascript

C:\Users\Vicky\workspace\LearningJavaScript\first.html:1
(function (exports, require, module, __filename, __dirname) { <!DOCTYPE html>
                                                              ^
    SyntaxError: Unexpected token <
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

2 个答案:

答案 0 :(得分:0)

我建议您从javascript中删除此<!DOCTYPE html>

即。 (function (exports, require, module, __filename, __dirname) { ... });

我猜这是因为你需要JQuery,其中包括Bootstrap才能工作。

尝试将此添加到您的代码中:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">

也可以找到here

答案 1 :(得分:0)

从评论中(由您自己发帖( The Code )),我做了一些编辑。
可能的isssue没有调用jQuery Library,你正在使用它。立即查看

&#13;
&#13;
function moveIt(){ 
var coords = new Array(10,50,100,130,175,225,260,300,320,350);
var x = coords[Math.floor((Math.random()*10))];
var y = coords[Math.floor((Math.random()*10))]; $("#elusiveText").css({"top": x + "px", "left": y + "px"});
}
&#13;
span{ background-color: #0066AA;
          color: #FFFFFF;
          font-weight: bold;
          border-color: #C0C0C0;
          border:2px solid;
          border-radius:5px;
          padding: 3px;
          position:absolute;
          top:150px;
          left:100px;
    }
&#13;
<head>
  <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
</head>
<body>
  <span id="elusiveText" onmouseover="moveIt()">Click Me</span> </body>
&#13;
&#13;
&#13;