target标签作用

_blank -- 在新窗口中打开链接
_parent -- 在父窗体中打开链接
_self -- 在当前窗体打开链接,此为默认值
_top -- 在当前窗体打开链接,并替换当前的整个窗体(框架页)

在 HTML 中,`target` 并非独立标签,而是 `<a>`、`<form>` 等标签的属性,用于指定链接或表单提交后,目标内容的显示方式。以下是其使用方法和相关知识: ### `<a>` 标签中的 `target` 属性 `<a>` 标签用于创建超链接,`target` 属性可控制链接页面的打开位置。常见取值如下: - `_self`:默认值,在当前窗口或框架中打开链接。 ```html <a href="https://www.example.com" target="_self">打开链接</a> ``` - `_blank`:在新窗口或新标签页中打开链接。 ```html <a href="https://www.example.com" target="_blank">在新窗口打开链接</a> ``` - `_parent`:在父框架中打开链接。若没有父框架,则等同于 `_self`。 ```html <frameset> <frame src="frame1.html"> <frame src="frame2.html"> </frameset> <frame src="frame3.html"> <a href="https://www.example.com" target="_parent">在父框架打开链接</a> </frame> ``` - `_top`:在整个浏览器窗口中打开链接,会取消所有框架。 ```html <frameset> <frame src="frame1.html"> <frame src="frame2.html"> </frameset> <frame src="frame3.html"> <a href="https://www.example.com" target="_top">在整个窗口打开链接</a> </frame> ``` ### `<form>` 标签中的 `target` 属性 `<form>` 标签用于创建 HTML 表单,`target` 属性可指定表单提交后响应页面的显示位置,取值与 `<a>` 标签类似。 - `_self`:在当前窗口或框架中显示表单提交后的响应页面。 ```html <form action="submit.php" method="post" target="_self"> <input type="text" name="username"> <input type="submit" value="提交"> </form> ``` - `_blank`:在新窗口或新标签页中显示表单提交后的响应页面。 ```html <form action="submit.php" method="post" target="_blank"> <input type="text" name="username"> <input type="submit" value="提交"> </form> ``` - `_parent`:在父框架中显示表单提交后的响应页面。 ```html <frameset> <frame src="frame1.html"> <frame src="frame2.html"> </frameset> <frame src="frame3.html"> <form action="submit.php" method="post" target="_parent"> <input type="text" name="username"> <input type="submit" value="提交"> </form> </frame> ``` - `_top`:在整个浏览器窗口中显示表单提交后的响应页面。 ```html <frameset> <frame src="frame1.html"> <frame src="frame2.html"> </frameset> <frame src="frame3.html"> <form action="submit.php" method="post" target="_top"> <input type="text" name="username"> <input type="submit" value="提交"> </form> </frame> ``` ### 自定义窗口名称 `target` 属性还可以指定自定义的窗口或框架名称,实现特定的显示效果。 ```html <a href="https://www.example.com" target="myWindow">在自定义窗口打开链接</a> <form action="submit.php" method="post" target="myWindow"> <input type="text" name="username"> <input type="submit" value="提交"> </form> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值