简体   繁体   English

Javascript无法与节点应用正确链接

[英]Javascript not linking properly with node app

Using Node/Express/EJS and I havent included any js files yet, well im starting to and cannot get my alert("working"); 使用Node / Express / EJS时,我还没有包含任何js文件,即时消息开始并且无法得到我的alert("working"); to work! 上班! Ironic huh. 讽刺吧。

The goal is to get learnJs.js to load in the browser to show the alert so I know things are working. 目的是让learningJs.js加载到浏览器中以显示警报,以便我知道一切正常。

Here is node including the directory: 这是包含目录的节点:

// Static Resource Inclusions
app.use(express.static(__dirname +"/styles"));
app.use(express.static(__dirname +"/img"));
app.use(express.static(__dirname +"/js"));
app.set("views", path.join(__dirname, "/views"));
app.set("view engine", "ejs");

Here is the file structure I have: 这是我拥有的文件结构:

[ [ 在此处输入图片说明

Here is the learnJs.js: 这是learnJs.js:

在此处输入图片说明

Here is the front end template, header.ejs and it gets called on every page: 这是前端模板header.ejs ,它在每个页面上都被调用:

<head>
<title>Memento</title>

<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="/styles.css">
<script type="text/javascript" src="/js/scripts/learnJs.js"></script>

您需要加载如下脚本,不需要/ js /

 <script type="text/javascript" src="scripts/learnJs.js"></script>

通过检查浏览器中的developer console ,确保将您的learnJs文件已加载到浏览器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM