58

我需要在网页中包含一个 javascript 文件。我写了以下内容:

include /../scripts/jquery.timeago.js

但我明白了

<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>

结果。但是我需要:

<script src="/Scripts/jquery.timeago.js" type="text/javascript"></script>

怎么做?

4

4 回答 4

95

把它放在你的玉文件中:

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

于 2013-01-16T09:16:04.240 回答
11

你可以把这段代码放在你的jade文件中:

   script(type='text/javascript' src='public/vendor/jquery/jquery.min.js')
于 2014-03-17T16:30:55.237 回答
9

此外,如果您想在您的翡翠文件中包含内联 js,您也可以执行以下操作:

script(type="text/javascript").
console.log('hello world');
于 2016-01-27T00:12:24.717 回答
2

将脚本添加到您的翡翠文件的语法是

script(src="",...,otherAttribute="")

像下面这样的示例,它将 Jquery Bootstraps 添加到页面。

  script( src="https://code.jquery.com/jquery-3.2.1.slim.min.js",  integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" ,crossorigin="anonymous")

script(src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js", integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q", crossorigin="anonymous")

  script( src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ,integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl", crossorigin="anonymous") 
于 2018-03-06T14:34:40.010 回答