属性是为HTML元素提供的附加信息。
为相同的HTML元素指定不同的属性,会呈现不同的功能或效果。
举个例子:
比如我们在上一篇中练习过的<a></a>标签构成的超链接元素中有一个href属性,这个属性指定的是点击后跳转的页面地址,相同的<a>标签改变href属性就能跳转不同的页面。例如
<a href="https://www.bilibili.com/read/cv2720755">歼-20战斗机</a>
<a href="http://mil.chinanews.com/mil/hd2011/2014/03-06/315569.shtml">歼-20战斗机</a><!-- 注释 看起来一样的超链接元素因为href属性不同,打开的页面也不同。-->
小伙伴们自己写的时候要注意使用半角符号,不然不能正确打开链接。
超链接元素中还有一个控制链接页面打开的属性叫做target,是用来控制新打开页面窗口的位置。下面我们就看看target属性为_blank和_parent的情况下的不同。例如
<a href="https://www.bilibili.com/read/cv2720755" target="_blank">歼-20战斗机</a>
<a href="http://mil.chinanews.com/mil/hd2011/2014/03-06/315569.shtml" target="_parent">歼-20战斗机</a><!-- 注释 看起来一样的超链接元素因为target属性不同,打开的页面所在窗口不同。-->
测试后,target="_blank"时,新页面在测试页面窗口旁边新建一个窗口打开。
target="_parent"时,新页面在原有测试页面窗口中打开。
如图所示:
左边为_blank,右边为_parent,点击左边链接后,新窗口在原有窗口旁边打开。如下图:
点击右侧