我已将用户定义的javascript函数包含在layout.jade中,如下所示:
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
script(type='text/javascript' src='../public/javascript/myjavascript.js')
body
block content
现在,如果我在index.js中包含来自myjavascript.js的函数,则不执行它,即使调用存在于生成的html中。 index.jade的代码:
extends layout
block content
h1= title
p Welcome to #{title}
script(type='text/javascript').
alerting();
myjavascript.js的代码:
function alerting(){
alert("working");
console.log("myjavascript called");
}
生成的渲染html:
...
<script type="text/javascript" src="../public/javascript/myjavascript.js"></script>
</head>
<body>
...
<script type="text/javascript">alerting();</script>
...
但是,如果我在jade模板中包含javascript inline,则会调用该函数,即以下代码显示一个警告窗口:
extends layout
block content
h1= title
p Welcome to #{title}
script(type='text/javascript').
alert("My alert");
你能指出我犯了哪个错误吗?