2013-01-15 55 views
43

我需要包含一个JavaScript文件到网页。我写了以下内容:Jade:如何包含一个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> 

如何做到这一点?

+0

['includes'](https://pugjs.org/language/includes.html)用于将一个帕格文件的内容包含到另一个帕格文件中。 '脚本'是你正在寻找的。 – TheCrazyProgrammer

回答

73

将这个在玉文件:

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

+21

不要忘记将它放在''标签的末尾,而不要放在''中,以使页面加载速度更快 –

8

你可以把这段代码在你的玉文件:

script(type='text/javascript' src='public/vendor/jquery/jquery.min.js') 
4

另外,如果你想包括您的玉石中内嵌的js你也可以执行以下操作:

script(type="text/javascript"). 
console.log('hello world'); 
1

添加脚本的语法您玉文件是

脚本(SRC = “”,......,otherAttribute = “”)

例如像下面的一个,增加了Jquery的白手起家到页面。

` 脚本(SRC = “https://code.jquery.com/jquery-3.2.1.slim.min.js”,完整性= “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 = ”匿名“)

脚本(SRC = ”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js“,完整性=” SHA384 -JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5 + 76PVCmYl“,crossorigin =”anonymous“)

`

+0

仅发布代码有点粗鲁,并不很有帮助。你介意解释一下吗?并可以添加一个链接到文档? – nicolallias

+0

很抱歉,我只是着急, 语法在玉 脚本添加脚本(SRC =“”,......,otherAttribute =“”) 并且可以添加任何地方在HTML页面中, 但上面的代码只是添加Jquery引导程序的一种快速方法,并且最好在关闭body标签之前添加它。 –

相关问题