我的NodeJS应用程序非常简单,但我在将JavaScript文件链接到其中遇到了困难。通常,您只需将脚本放在标题中即可。显然,这在Node上不起作用,因此我尝试通过sendFile和其他一些方法进行链接,但没有一种方法适用。
我的JavaScript非常简单:
var express = require('express');
var app = express();
app.get('/',function(req, res) {
res.sendFile(__dirname + '/index.html');
res.send()
});
app.listen(8888)
我的HTML也很简单:
<html>
<head>
<title>Charter</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container" style="width:100%; height:400px;"></div>
<button id="button" class="autocompare" onclick="plotNewChart()">Add series</button>
<script type="text/javascript">
$(function () { $('#container').highcharts({ chart: { events: { addSeries: function () { var label = this.renderer.label('A series was added, about to redraw chart', 100, 120).attr({ fill: Highcharts.getOptions().colors[0], padding: 10, r: 5, zIndex: 8 }) .css({ color: '#FFFFFF' }) .add(); setTimeout(function () { label.fadeOut(); }, 1000); } } }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, series: [{ data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] }] }); });
</script>
</body>
</html>
我想要做的是链接另一个文件
myJS.js
,但不知道如何在不使用传统的 `` 标签的情况下实现。
node filename.js
启动它。 - Christopher Marshall