我正在尝试使用express框架和ejs来获取Typed.JS,但很难使其正常工作。
我已经在我的app.js文件中安装并需要typed.js和jquery,但是由于某种原因从库中导入时出现错误。
我还尝试通过CDN链接typed.js并将javascript放在ejs模板的script标签中,但是没有运气
//set all the dependencies in app.js
var express = require("express"),
app = express(),
bodyParser = require ("body-parser"),
mongoose = require("mongoose"),
methodOverride = require("method-override"),
jquery = require("jquery"),
Typed = require("typed.js");
//Routes in app.js
app.get("/", function(req, res){
res.render("index", {Typed: Typed});
});
// In the index.ejs file
<script>
var typed = new Typed('#typed', {
stringsElement: '#typed-strings'
});
</script>
<div id="typed-strings">
<p>Typed.js is a <strong>JavaScript</strong> library.</p>
<p>It <em>types</em> out sentences.</p>
</div>
<span id="typed"></span>