Jade:如何包含javascript文件

Ole*_* Sh 51 express pug

我需要在网页中加入一个javascript文件.我写了以下内容:

include /../scripts/jquery.timeago.js
Run Code Online (Sandbox Code Playgroud)

但我明白了

<script>/*
 * timeago: a jQuery plugin, version: 0.8.2 (2010-02-16)
 * @requires jQuery v1.2.3 or later
 *
 * Timeago is a jQuery plugin that makes it easy to support automatically
 * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
 *
 * For usage and examples, visit:
 * http://timeago.yarp.com/
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright (c) 2008-2010, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
 */
(function($) {
....
</script>
Run Code Online (Sandbox Code Playgroud)

结果.但是我需要:

<script src="/Scripts/jquery.timeago.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

怎么做?

Ehe*_*Tov 87

把它放在你的玉文件中:

script(src="/Scripts/jquery.timeago.js")

  • 不要忘记把它放在你的`<body>`标签的末尾而不是你的`<head>`以使页面加载更快 (23认同)

Anu*_*ngh 10

您可以将此代码放在您的jade文件中:

   script(type='text/javascript' src='public/vendor/jquery/jquery.min.js')
Run Code Online (Sandbox Code Playgroud)


Law*_*ang 8

此外,如果您想在jade文件中包含内联j,您还可以执行以下操作:

script(type="text/javascript").
console.log('hello world');
Run Code Online (Sandbox Code Playgroud)