HTML a target 属性

htmlweb developmentfront end technology更新于 2025/7/14 9:16:17

<a> 元素的 target 属性用于设置链接文档的打开位置。您可以将文档设置为在新窗口中打开、在同一框架中打开、在父框架中打开等。

以下是语法 −

<a target="_blank|_self|_parent|_top| frame">

其中,_blank 用于在新窗口或标签页中打开链接文档,_self 用于在点击的同一框架中打开链接文档,_parent 用于在父框架中打开文档,_top 用于在整个窗口主体中打开链接文档,frame 用于在指定的框架中打开链接文档。

现在让我们看一个在 <a> 元素中实现 target 属性的示例 −

示例

<!DOCTYPE html>
<html>
<body>
<h2>Learning is Fun</h2>
   <p><strong>Note −</strong> The links will open in new window.</p>
   <p><a href="https −//www.tutorialspoint.com/tutorialslibrary.htm" target="_blank">Tutorials Library</a><br>
   <a href="https −//www.tutorialspoint.com/programming_examples/" target="_blank">Codes</a><br>
   <a href="https −//www.tutorialspoint.com/computer_glossary.htm" target="_blank">Computer Glossary</a>
<br>
</body>
</html>

这将产生以下输出。以下链接将在新窗口中打开 −

在上面的示例中,我们在 target 属性中设置了目标 −

<a href="https −//www.tutorialspoint.com/tutorialslibrary.htm" target="_blank"> 教程库 </a>

上面设置的属性值为 _blank,表示会在新窗口中打开 href 属性中的链接 −

target="_blank"

相关文章


有用资源