我們如何在HTML中包含一個錨點?

WBOY
發布: 2023-08-31 15:21:06
轉載
861 人瀏覽過

我們如何在HTML中包含一個錨點?

在本文中,我們將執行如何在 HTML 中包含錨點的任務。讓我們深入閱讀本文,以了解 HTML 中的錨點。

錨元素用於將來源錨點連結到目標錨點。目標是來源錨點連接到的資源,而來源是指向另一個網站的文字、圖片或按鈕。

超連結是讓網路成為資訊高速公路的關鍵技術之一。

為了更了解如何在 HTML 中包含錨點,讓我們看看以下範例

範例 1

在下面的範例中,我們將建立一個跳躍錨連結。

<!DOCTYPE html>
<html>
<head>
   <style>
      .main-content {
         height: 90vh;
         text-align: justify;
      }
   </style>
</head>
<body>
   <h2 id="tutorials">Tutorials Point</h2>
   <p class="main-content">
   Tutorials Point originated from the idea that there exists a class of readers who
   respond better to online content and prefer to learn new skills at their own pace
   from the comforts of their drawing rooms.The journey commenced with a single tutorial
   on HTML in 2006 and elated by the response it generated, we worked our way to adding
   fresh tutorials to our repository which now proudly flaunts a wealth of tutorials and
   allied articles on topics ranging from programming languages to web designing to academics
   and much more.</p>
   <p>Click To
      <a href="#tutorials">Jump</a>.
   </p>
</body>
</html>
登入後複製

在執行上述腳本時,會彈出輸出窗口,顯示上述腳本中使用的文字以及提到的錨標記“點擊跳轉”,該錨標記允許使用者跳到按下時頁面開始。

範例 2

考慮到以下情況,我們正在建立一個從另一個網頁連結到錨點的範例。

<!DOCTYPE html>
<html>
<body>
   <h2 id="Tutorials">TutorialsPoint</h2>
   <p>Tutorials Point originated from the idea that there exists a class of readers
   who respond better to online content and preferto learn new skills at their own
   place from the comforts of their drawing rooms.</p>
   <p>
      <a href="https://www.tutorialspoint.com/market/index.asp">Go To The Course Page.</a>
   </p>
   <p>
      <a href="https://www.tutorialspoint.com/latest/ebooks">Search For Ebooks.</a>
   </p>
</body>
</html>
登入後複製

執行腳本時,它將產生一個輸出,顯示上述腳本中使用的文字以及使用錨標記附加到網頁的連結。當用戶單擊連結時,它將打開新頁面。

範例 3:使用 JavaScript

查看以下範例,我們將建立一個指向 javascript 的連結。

<!DOCTYPE html>
<html>
<body>
   <a href="javascript:alert('Welcome To TutorialsPoint!');">Click To Execute</a>
</body>
</html>
登入後複製

執行給定腳本時,它將提供一個輸出,其中包括使用帶有文字「點擊執行」的錨點放置在網頁上的連結。

如果使用者點擊鏈接,則會觸發腳本並顯示警告“歡迎來到教程點”。

以上是我們如何在HTML中包含一個錨點?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!