如何在 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.