如何在 HTML 頁面中使用 href 屬性?


href 屬性指定連結指向的頁面的 URL(href 屬性指定連結的目標)。

我們應該將 href 屬性與 <a> 標籤一起使用,這樣它才會成為超連結。此 <a> 標籤應在 <body>…</body> 標籤內使用。

語法

以下是 <a> 標籤的語法,它使用 href 屬性來指定連結地址。

<a href="link address">link text</a>

示例

以下是如何在 HTML 頁面中使用 href 屬性的示例程式。

<!DOCTYPE html> <html> <body> <p><a href="https://www.Brave.com">Click this to navigate to the Brave home page</a></p> </body> </html>

如何連結同一頁面的某個部分?

我們可以使用以下語法連結同一頁面的某個部分。

語法

以下是連結同一網頁某個部分的語法。

<a href="#section id">heading of the section</a>

示例

以下是連結同一網頁某個部分的示例。

<!DOCTYPE html> <html> <body> <a href="#RAJYA SABHA">RAJYA SABHA</a> <h3>LOK SABHA</h3> <p>Lok Sabha is composed of representatives of the people chosen by direct election. <br> The maximum strength of the House of the Constitution is 552,<br> which is made up by election of upto 530 members to represent the States, <br> upto 20 members to represent the Union Territories and not more than two members of the <br> Anglo-Indian Community to be nominated by the Hon'ble President.</p> <h3 id="RAJYA SABHA">RAJYA SABHA</h3> <p>The ‘Council of States’ which is also known as Rajya Sabha,<br> a nomenclature that was announced by the chair in the House on the 23rd August, <br> 1954 has its own distinctive features.<br> The origin of the second Chamber can be traced to the Montague-Chelmsford Report of 1918. <br>The Government of India Act, <br>1919 provided for the creation of a ‘Council of State’ as a second chamber of the then legislature <br> with a restricted franchise which actually came into existence in 1921.<br> The Governor-General was the ex-officio President of the then Council of State. The Government of India Act,<br> 1935, hardly made any changes in its composition.</p> </body> </html>

當我們點選 Rajya sabha 時,它會導航到同一頁面上的 Rajya sabha 部分。

如何連結電話號碼?

我們可以使用以下語法連結電話號碼。

語法

以下是連結電話號碼的語法。

<a href="tel: phone number">phone number</a>

透過在 href 屬性中使用 tel:,我們可以連結到電話號碼。

示例

以下是將電話號碼連結到網頁的示例程式。

<!DOCTYPE html> <html> <body> <p><a href="tel:9381276097">9381276097</a></p> </body> </html>

如何連結到郵件地址?

我們可以使用以下語法連結到郵件地址。

語法

以下是將郵件地址連結到網頁的語法。

<a href="mailto:xx@gmail.com">xx@gmail.com</a>

與連結手機號碼的方式相同。我們在 href 屬性中使用 mailto 而不是 tel。

示例

以下是將郵件地址連結到網頁的示例程式。

<!DOCTYPE html> <html> <body> <p><a href="mailto:lokeshnayak@gmail.com">lokeshnayak@gmail.com</a></p> </body> </html>

當我們點選電子郵件地址時,它會將我們導航到系統中的預設郵件應用程式。

更新於: 2022-11-11

2K+ 瀏覽量

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.