希望您一切安好。
我突然无法在jade模板中呈现任何外部javascript!为了找出问题的根源,我将其剥离到最少:
Node 0.6.11,Express 2.5.8,jade 0.20.3
app.js
var express = require('express')
, routes = require('./routes');
var app = module.exports = express.createServer();
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
app.get('/', function(req, res){
res.render('index', { title: 'Express' });
});
app.listen(3000);
layout.jade
!!!
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
script(type='text/javascript', src='/javascripts/script.js')
body!= body
script.js
alert('hello!');
在我运行服务器并加载http://localhost:3000/时,我应该立即收到“hello!”消息,但它直接运行到正常页面。 此外,如果我手动输入
script
alert('hello!')
将内容添加到layout.jade模板中后,我收到了应有的消息。只是静态脚本没有加载。我确信'script.js'在'/public/javascripts/'中,就像它应该在的位置一样。任何建议都非常受欢迎!提前致谢。