jquery - 运行node.js里程表中间件

标签 jquery node.js express middleware node-modules

在我的 Node.js Express 应用程序中,我尝试从 here 运行里程表中间件。我通过以下方式将其包含在我的代码文件中:

var odometer = require('odometer');

当我运行应用程序时,在控制台中收到错误消息

ReferenceError: document is not defined
    at Object.<anonymous> (C:\xampp\htdocs\ri\node_modules\odometer\odometer.js:
33:27)

显然document在服务器端不可用,里程表的主要javascript文件使用document。所以

1)如何运行中间件?

2)如果无法运行这个,还有其他替代方案吗?

最佳答案

里程表不是中间件。它适用于浏览器,因此只需包含到您的 html 文件中即可。

How To Use 来自文档..

Add the js and a theme file to your page:

<link rel="stylesheet" href="path/to/your/file/odometer-theme-car.css" />
<script src="path/to/your/file/odometer.js"></script>

Any element with class name "odometer" will automatically be made into an Odometer! When you want to update the value, simply update it the same way you normally would.

element.innerHTML = 123 // Native, or...
$('.odometer').html(123) // with jQuery

关于jquery - 运行node.js里程表中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27566338/

相关文章:

jquery - 如何在调整窗口大小时调整 div 最大高度?

Jquery 插件 blockUI 不支持 ajax

jquery - 同时平滑地重新排序并在悬停时出现新的词段

javascript - 事件函数问题

javascript - 变量不保留值

node.js - 与 Docker 和 Bitbucket 管道的集成测试

javascript - 如何在 Express JS 的不同文件中创建自己的异步函数

javascript - 提高从 API 获取条件数据的速度

javascript - Express 提供的客户端 React 应用程序上一致的 url 路由

javascript - 如何使用 Node - Express - Passport 使用 "/"进行登录和登录主页?