简体   繁体   中英

How to add custom js to HTML

So I am using Node.js for my Web Server. I installed Typed.js Now I am having poblem implementing it in my HTML file.

I used the following code in css/script.js:

var typed =new Typed('#typed',{
    strings: ["First sentence.", "Second sentence."],
    typeSpeed: 30
  })

In the HTML file :

<h1 id="typed"></h1>
....body....
<script src="css/script.js></script>

Also I included the Script file at the bottom of index.html page. What am I doing wrong here.

Edit: I checked the console log it says localhost:3000/css/script.js not found. I searched a little bit came across using static files in express.js by this method app.use(express.static('public')) but still shows the same error File not Found.

Node.js is server-side framework, but you are just developing client-side logic with HTML/JavaScript here.

Are you just using package manager such as npm and yarn , but not Node.js?

You should include the Typed.js in your HTML like this:

<script src="node_modules/typed.js/lib/typed.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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