日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

javascript脚本_使用脚本src属性将JavaScript链接到HTML

發布時間:2023/11/29 javascript 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 javascript脚本_使用脚本src属性将JavaScript链接到HTML 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

javascript腳本

The ‘src’ attribute in a tag is the path to an external file or resource that you want to link to your HTML document.

標記中的'src'屬性是您要鏈接到HTML文檔的外部文件或資源的路徑。

For example, if you had your own custom JavaScript file named ‘script.js’ and wanted to add its functionality to your HTML page, you would add it like this:

例如,如果您有一個名為'script.js'的自定義JavaScript文件,并想將其功能添加到HTML頁面,則可以這樣添加:

<!DOCTYPE html> <html lang="en"><head><title>Script Src Attribute Example</title></head><body><script src="./script.js"></script></body> </html>

This would point to a file named ‘script.js’ that is in the same directory as the .html file. You can also link to other directories by using ’..’ in the file path.

這將指向名為“ script.js”的文件,該文件與.html文件位于同一目錄中。 您也可以在文件路徑中使用“ ..”鏈接到其他目錄。

<script src="../public/js/script.js"></script>

This jumps up one directory level then into a ‘public’ directory then to a ‘js’ directory and then to the ‘script.js’ file.

這將跳到一個目錄級別,然后跳到“ public”目錄,再跳到“ js”目錄,再跳到“ script.js”文件。

You can also use the ‘src’ attribute to link to external .js files hosted by a third party. This is used if you don’t want to download a local copy of the file. Just note that if the link changes or network access is down, then the external file you are linking to won’t work.

您還可以使用'src'屬性鏈接到第三方托管的外部.js文件。 如果您不想下載文件的本地副本,則使用它。 請注意,如果鏈接更改或網絡訪問斷開,則鏈接到的外部文件將無法工作。

This example links to a jQuery file.

本示例鏈接到jQuery文件。

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

更多信息: (More Information:)

MDN Article on the HTML

有關HTML的MDN文章

翻譯自: https://www.freecodecamp.org/news/link-javascript-to-html-with-the-src/

javascript腳本

總結

以上是生活随笔為你收集整理的javascript脚本_使用脚本src属性将JavaScript链接到HTML的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。