1. 首页
  2. HTML

HTML – 文本链接

网页可以包含各种链接,可以直接将您带到其他页面甚至是给定页面的特定部分。这些链接称为超链接。

超链接允许访问者通过单击单词,短语和图像在网站之间导航。因此,您可以使用网页上提供的文本或图像创建超链接。

html

注意 – 我建议您阅读有关了解URL的简短教程

链接文件

使用HTML标记<a>指定链接。此标记称为锚标记,打开的<a>标记和结束</a>标记之间的任何内容都将成为链接的一部分,用户可以单击该部分以访问链接的文档。以下是使用<a>标签的简单语法。

<a href = "Document URL" ... attributes-list>Link Text</a> 

让我们尝试以下链接http://www.seo0j.com/的示例 –

<!DOCTYPE html>
<html>
   
   <head>
      <title>Hyperlink Example</title>
   </head>
	
   <body>
      <p>Click following link</p>
      <a href = "http://www.seo0j.com/" target = "_self">Tutorials Point</a>
   </body>
	
</html>

这将产生以下结果,您可以单击生成的链接以访问Tutorials Point的主页(在此示例中)。

目标属性

我们在前面的例子中使用了target属性。此属性用于指定打开链接文档的位置。以下是可能的选择 –

Sr.No 选项和说明
1 _空白

在新窗口或选项卡中打开链接的文档。

2 _自

在同一帧中打开链接的文档。

3 _parent

在父框架中打开链接的文档。

4 _最佳

在窗口的整个正文中打开链接的文档。

targetframe

在指定的目标框架中打开链接的文档。

尝试以下示例来了解为target属性指定的几个选项的基本差异。

<!DOCTYPE html>
<html>

   <head>
      <title>Hyperlink Example</title>
      <base href = "http://www.seo0j.com/">
   </head>
	
   <body>
      <p>Click any of the following links</p>
      <a href = "/html/index.htm" target = "_blank">Opens in New</a> |
      <a href = "/html/index.htm" target = "_self">Opens in Self</a> |
      <a href = "/html/index.htm" target = "_parent">Opens in Parent</a> |
      <a href = "/html/index.htm" target = "_top">Opens in Body</a>
   </body>

</html>

这将产生以下结果,您可以在其中单击不同的链接以了解为目标属性指定的各种选项之间的差异。

使用基本路径

链接与同一网站相关的HTML文档时,不需要为每个链接提供完整的URL。如果在HTML文档标题中使用<base>标记,则可以删除它。此标记用于为所有链接提供基本路径。因此,您的浏览器将连接到此基本路径的相对路径,并将创建一个完整的URL。

下面的示例使用<base>标记指定基本URL,稍后我们可以使用所有链接的相对路径,而不是为每个链接提供完整的URL。

<!DOCTYPE html>
<html>

   <head>
      <title>Hyperlink Example</title>
      <base href = "http://www.seo0j.com/">
   </head>
	
   <body>
      <p>Click following link</p>
      <a href = "/html/index.htm" target = "_blank">HTML Tutorial</a>
   </body>
	
</html>

这将产生以下结果,您可以在其中单击链接生成的HTML教程以访问HTML教程。

现在给定URL <a href =“/ html / index.htm”被视为<ahref =“http://www.seo0j.com/html/index.htm”

链接到页面部分

您可以使用name属性创建指向给定网页的特定部分的链接。这是一个两步过程。

 – HTML5中不推荐使用name属性。不要使用此属性。请改用idtitle属性。

首先使用<a …>标记创建指向您希望在网页中访问的地点的链接,如下所示 –

<h1>HTML Text Links <a name = "top"></a></h1>

第二步是创建一个超链接来链接文档和您想要到达的位置 –

<a href = "/html/html_text_links.htm#top">Go to the Top</a>

这将生成以下链接,您可以在其中单击生成的链接转到顶部以访问HTML文本链接教程的顶部。

设置链接颜色

您可以使用<body>标记的linkalinkvlink属性设置链接,活动链接和访问链接的颜色。

将以下内容保存在test.htm中,并在任何Web浏览器中打开它,以查看linkalinkvlink属性的工作方式。

<!DOCTYPE html>
<html>
   
   <head>
      <title>Hyperlink Example</title>
      <base href = "http://www.seo0j.com/">
   </head>
	
   <body alink = "#54A250" link = "#040404" vlink = "#F40633">
      <p>Click following link</p>
      <a href = "/html/index.htm" target = "_blank" >HTML Tutorial</a>
   </body>
   
</html>

这将产生以下结果。只需在点击之前检查链接的颜色,然后在激活时检查其颜色以及访问链接时的颜色。

下载链接

您可以创建文本链接以使PDF或DOC或ZIP文件可下载。这很简单; 您只需要提供可下载文件的完整URL,如下所示 –

<!DOCTYPE html>
<html>

   <head>
      <title>Hyperlink Example</title>
   </head>
	
   <body>
      <a href = "http://www.seo0j.com/page.pdf">Download PDF File</a>
   </body>
	
</html>

这将产生以下链接,并将用于下载文件。

 

文件下载对话框

有时,您希望提供一个用户单击链接的选项,它会向用户弹出“文件下载”框,而不是显示实际内容。这非常简单,可以使用HTTP响应中的HTTP标头来实现。

例如,如果要从给定链接下载文件名文件,则其语法如下所示。

#!/usr/bin/perl

# Additional HTTP Header
print "Content-Type:application/octet-stream; name = \"FileName\"\r\n";
print "Content-Disposition:attachment; filename = \"FileName\"\r\n\n";

# Open the target file and list down its content as follows
open( FILE, "<FileName" );

while(read(FILE, $buffer, 100)){
   print("$buffer");
}

原创文章,作者:零久SEO,如若转载,请注明出处:http://www.seo0j.com/332.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论列表(14条)

  • lebron 15 2020年2月23日 下午9:57

    I precisely had to thank you so much once more. I’m not certain the things that I might have used without these secrets provided by you regarding such industry. This was the intimidating difficulty in my position, nevertheless coming across this expert manner you handled the issue made me to weep over fulfillment. I am just happy for this help and in addition hope you comprehend what a powerful job you are always providing educating most people via your webblog. Probably you have never come across all of us.

  • yeezy 2020年2月26日 上午9:20

    I together with my buddies happened to be taking note of the best tactics found on your web blog while immediately came up with a terrible feeling I never expressed respect to the website owner for those strategies. The men ended up for this reason thrilled to see them and have now simply been tapping into these things. Appreciation for getting so kind as well as for having such extraordinary useful guides most people are really desirous to learn about. My sincere apologies for not expressing gratitude to earlier.

  • kate spade handbags 2020年2月29日 上午5:00

    Thanks so much for providing individuals with an exceptionally marvellous possiblity to read in detail from here. It’s always so pleasing and jam-packed with a great time for me personally and my office fellow workers to search your web site nearly 3 times per week to learn the new guidance you have. And indeed, I’m so actually impressed with your mind-blowing ideas you serve. Some 2 ideas in this posting are really the very best we have had.

  • jordan shoes 2020年3月2日 下午4:14

    My husband and i were now thankful when Emmanuel managed to do his research through the entire precious recommendations he gained from your web site. It’s not at all simplistic just to continually be freely giving facts the rest have been selling. Therefore we do know we have the blog owner to appreciate for that. The specific explanations you have made, the easy site menu, the friendships your site aid to engender – it’s got many powerful, and it is facilitating our son and the family feel that the theme is pleasurable, and that’s incredibly important. Thank you for all the pieces!

  • supreme hoodie 2020年3月5日 上午7:41

    I wish to show thanks to this writer just for rescuing me from this particular crisis. Just after browsing throughout the the net and obtaining proposals which were not pleasant, I believed my entire life was done. Living devoid of the approaches to the problems you have solved by means of your good posting is a critical case, and those which might have negatively damaged my entire career if I had not discovered your blog post. That mastery and kindness in touching every item was vital. I am not sure what I would have done if I hadn’t encountered such a step like this. I can also at this time look forward to my future. Thanks a lot so much for the professional and sensible help. I will not hesitate to recommend the sites to anyone who should have guidelines about this problem.

  • supreme hoodie 2020年3月8日 上午2:22

    I wish to show my appreciation to the writer just for rescuing me from this matter. Right after checking throughout the world-wide-web and obtaining opinions which were not beneficial, I assumed my entire life was well over. Living devoid of the strategies to the issues you have resolved as a result of your main article is a serious case, as well as ones which might have negatively damaged my entire career if I hadn’t come across your site. Your main capability and kindness in touching all things was invaluable. I don’t know what I would’ve done if I had not discovered such a subject like this. I’m able to at this moment relish my future. Thank you very much for the skilled and amazing guide. I won’t hesitate to refer your blog post to anyone who needs to have guidelines on this topic.

  • nike max 2020年3月10日 上午9:04

    I intended to write you that tiny observation to help say thanks over again for all the striking secrets you have documented here. It’s so shockingly open-handed with you to grant easily all most people might have sold as an e book to generate some bucks for themselves, most notably seeing that you might well have done it in the event you considered necessary. These tips in addition worked to become fantastic way to comprehend most people have similar eagerness like my personal own to know very much more when considering this condition. I am certain there are many more fun situations in the future for folks who examine your blog.

  • moncler outlet 2020年3月14日 上午3:54

    I just wanted to write a small word so as to appreciate you for these remarkable ideas you are placing on this website. My considerable internet look up has at the end been honored with useful ideas to go over with my two friends. I would say that many of us readers are unequivocally fortunate to live in a very good community with many special individuals with interesting guidelines. I feel somewhat privileged to have encountered your web pages and look forward to so many more brilliant moments reading here. Thanks once more for all the details.

  • yeezy supply 2020年3月17日 上午2:17

    I precisely wanted to appreciate you once again. I am not sure the things I would’ve followed in the absence of the type of hints shown by you concerning such subject. This has been a very daunting condition in my circumstances, nevertheless taking a look at a expert tactic you resolved it made me to weep for fulfillment. I am just grateful for your service and in addition hope that you are aware of a great job you’re accomplishing instructing some other people through the use of your websites. I am sure you haven’t come across any of us.

  • nike shoes 2020年3月19日 上午9:01

    I wish to get across my respect for your kind-heartedness for men who have the need for guidance on this one area. Your real dedication to passing the message up and down had become pretty interesting and have in most cases helped some individuals much like me to achieve their endeavors. The insightful guidelines indicates much to me and somewhat more to my colleagues. Many thanks; from each one of us.

  • supreme clothing 2020年3月22日 上午6:43

    I wish to express my thanks to the writer just for bailing me out of this particular difficulty. As a result of browsing through the online world and obtaining solutions which are not powerful, I thought my entire life was gone. Being alive minus the answers to the problems you’ve solved through your good short article is a critical case, as well as the kind which may have in a negative way affected my entire career if I had not discovered your site. Your good training and kindness in dealing with every aspect was priceless. I’m not sure what I would’ve done if I had not encountered such a solution like this. I’m able to at this time relish my future. Thanks for your time very much for your specialized and amazing help. I will not think twice to propose your web page to any person who ought to have support on this topic.

  • adidas stan smith 2020年3月25日 上午3:23

    I in addition to my guys happened to be reading through the best guidelines from your web site and then immediately came up with an awful suspicion I had not thanked the web site owner for them. These young boys became for that reason stimulated to study them and have in effect undoubtedly been using them. We appreciate you simply being really thoughtful and also for using certain cool areas most people are really needing to be informed on. My very own sincere apologies for not expressing appreciation to you earlier.

  • michael kors handbags 2020年3月27日 上午10:40

    I would like to show my affection for your generosity for those people who require help with that study. Your special commitment to getting the message all over turned out to be remarkably interesting and have consistently helped others just like me to realize their ambitions. Your personal invaluable tips and hints can mean a lot to me and far more to my fellow workers. Warm regards; from all of us.

  • supreme clothing 2020年3月31日 上午4:28

    I intended to write you a little note to be able to say thanks a lot yet again on your striking principles you’ve documented on this site. It is extremely open-handed with you to supply unreservedly what exactly a few people might have advertised as an electronic book to help make some money on their own, especially considering that you might well have tried it in the event you desired. Those ideas likewise served to be a great way to know that other individuals have a similar interest like mine to find out a lot more on the topic of this problem. Certainly there are several more pleasurable occasions in the future for many who find out your blog.

联系我们

15555333984

在线咨询:点击这里给我发消息

邮件:lxa6@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code