使用链接和脚本标记引用JavaScript源有什么区别? [英] What's the difference between using link and script tag to reference JavaScript source?
问题描述
我尝试过使用以下两个source-reference-lines 。他们都编译。但有什么区别?
I've tried using both the following source-reference-lines. They both compile. But what is the difference?
第一种方法:
<script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
第二种方法:
<link href="~/Scripts/jquery-1.4.1.js" type="text/javascript" />
注意:还有类似的 < a href =https://stackoverflow.com/questions/51105967/difference-between-script-and-link-as-script> 脚本
与<$之间的差异c $ c> link as =script tags ,询问< link href =js / script.jsas =脚本>
,这是不同的。
Note: There's also the similar Difference between script
and link as="script"
tags which asks about <link href="js/script.js" as="script">
, which is different.
推荐答案
link
标签用于关联样式表或任何其他链接文档,而不是包含javascript文件。
link
tag is used to relate stylesheets or any other linked documents instead of including javascript files.
HTML 链接元素 < link>
指定当前文档与其他文档之间的关系。此元素的可能用途包括定义导航的关系框架并将文档链接到样式表。
The HTML Link Element <link>
specifies relationships between the current document and other documents. Possible uses for this element include defining a relational framework for navigation and linking the document to a style sheet.
rel
属性:
rel
Attribute:
此属性指定链接文档与当前文档的关系。该属性必须是以空格分隔的链接类型值列表。此属性的最常见用法是指定外部样式表的链接:rel属性设置为样式表,href属性设置为外部样式表的URL以格式化页面。 WebTV还支持使用rel的下一个值来预加载文档系列中的下一页。
This attribute names a relationship of the linked document to the current document. The attribute must be a space-separated list of the link types values. The most common use of this attribute is to specify a link to an external style sheet: the rel attribute is set to stylesheet, and the href attribute is set to the URL of an external style sheet to format the page. WebTV also supports the use of the value next for rel to preload the next page in a document series.
可能的值:
-
替代 - 文档的替代版本(即打印页面,已翻译或镜像)
alternate - An alternate version of the document (i.e. print page, translated or mirror)
样式表 - 文档的外部样式表
stylesheet - An external style sheet for the document
开始 - 选择中的第一个文档
start - The first document in a selection
next - 下一个文档在选择中
next - The next document in a selection
上一页 - 选择中的上一个文档
prev - The previous document in a selection
内容 - 文档的目录
index - 索引文件
词汇表 - 文件中使用的词汇词汇表(解释)
glossary - A glossary (explanation) of words used in the document
版权 - 包含版权信息的文件
copyright - A document containing copyright information
章 - 文档的一章
部分 - 文件的一部分
section - A section of the document
子部分 - 文件的一个小节
subsection - A subsection of the document
附录该文件的附录
帮助帮助文档
书签相关文档
快捷方式图标文档的相关(收藏夹图标)图片
shortcut icon A related (favorite icon) image of the document
虽然 HTML 脚本元素 < script>
用于在HTML或XHTML文档中嵌入或引用可执行脚本。
While The HTML Script Element <script>
is used to embed or reference an executable script within an HTML or XHTML document.
这篇关于使用链接和脚本标记引用JavaScript源有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!