html中a标签的用法 html常用标签大全
这篇文章给大家聊聊关于html中a标签的用法,以及html常用标签大全对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。
html中a标签href=""的几种用法介绍
众所周知,a标签的最重要功能是实现超链接和锚点。而且,大多数人认为a标签最重要的作用是实现超链接,今天我刚好碰到a标签的一种写法<a rel="external nofollow" rel="external nofollow" rel="external nofollow" href="javascript:;"></a>,所以就来整理下a标签中href的几种用法。
一、Js的几种调用方法(参考总结的)
1、
a rel="external nofollow" href="javascript:j
s_method();"这是常用的方法,但是这种方法在传递this等参数的时候很容易出问题,而且javascript:协议作为a的href属性的时候不仅会导致不必要的触发window.onbeforeunload事件,在IE里面更会使gif动画图片停止播放。W3C标准不推荐在href里面执行javascript语句
2、
a rel="external nofollow" rel="external nofollow" href="javascript:void(0);" onclick="js_method()"这种方法是很多网站最常用的方法,也是最周全的方法,onclick方法负责执行js函数,而void是一个操作符,void(0)返回undefined,地址不发生跳转。而且这种方法不会像第一种方法一样直接将js方法暴露在浏览器的状态栏。
3、
a rel="external nofollow" rel="external nofollow" rel="external nofollow" href="javascript:;" onclick="js_method()"这种方法跟跟2种类似,区别只是执行了一条空的js代码。
4、
a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#" onclick="js_method()"这种方法也是网上很常见的代码,#是标签内置的一个方法,代表top的作用。所以用这种方法点击后网页后返回到页面的最顶端。
5、
a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#" onclick="js_method();return false;"这种方法点击执行了js函数后return false,页面不发生跳转,执行后还是在页面的当前位置。
综合上述,在a中调用js函数最适当的方法推荐使用:
<a rel="external nofollow" rel="external nofollow" href="javascript:void(0);" onclick="js_method()"></a>
<a rel="external nofollow" rel="external nofollow" rel="external nofollow" href="javascript:;" onclick="js_method()"></a>
<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#" onclick="js_method();return false;"></a>二、rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"的作用
a中rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"表示回到最顶部。如果当前页面中需要滚动的话,那么用这种方式就可以直接回到顶部。比如有些网站会在右下角制作一个图标按钮,回到顶部,那么此时可以考虑用这种最简单的方式实现。
<span style="font-size:14px;"><a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#">回到最顶端</a></span>三、rel="external nofollow" href="URL"的作用
1、URL为绝对URL
此时指向另一个站点,比如
rel="external nofollow" rel="external nofollow" href="",那么点击时就会直接跳转到这个链接的页面。
2、URL为相对URL
此时指向站点内的某个文件,比如rel="external nofollow" href="/test.doc",那么点击时就会直接下载文件。
3、锚 URL
此时指向页面中的锚,比如rel="external nofollow" href="#top",那么点击时就会到当前页面中id="top"的这个锚点,实现当前页面的所谓跳转。用的最多就是在可滚动页面中,添加菜单,可以直接回到页面中的某个部分的内容。
即所有的三种代码样例:
<a rel="external nofollow" rel="external nofollow" href="">超链接</a>
<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#">回到最顶端</a>
<a rel="external nofollow" href="css/css1.css">文件链接</a>
HTML a 标签的基本用法和常用属性
1.href属性:用于指示链接的目标,该属性对于a标签来说必不可少。
言成科技2.title属性:当用户的鼠标移入超链接时,会显示title属性的具体属性值
言成科技3.target属性;用于控制链接页面打开的位置。
_blank:浏览器总在一个新打开、未命名的窗口中载入目标文档
言成科技_self:默认状态,在当前页面/目标中打开被链接文档
言成科技Tips:所有属性当中,使用最为频繁的是_self和_blank,由于默认打开方式为_self,所以,通常在需要打开新页面时才会使用target=“_blank”的属性设置。对于_parent、_top、framename,当前都已经不再使用,此处便不再提及。
想了解更多,请点击:《如何实现兼容IE6的a标签鼠标移入效果(hover效果)》
html的a标签是什么
在HTML中a标签就是<a></a>或者大写字母A。其中的a是anchor的缩写。这些标签的作用是标明超连接的起始位置或目的位置。
<a>标签可定义锚。锚有两种用法:
通过使用href属性,创建指向另外一个文档的链接通过使用name或id属性,创建一个文档内部的书签<a>元素最重要的属性是href属性,它指定链接的目标。
在所有浏览器中,链接的默认外观是:未被访问的链接带有下划线而且是蓝色的已被访问的链接带有下划线而且是紫色的活动链接带有下划线而且是红色的。
扩展资料:
html的a标签实例:
<aname="tips">UsefulTipsSection</a>然后,我们创建指向相同文档中“有用的提示”部分的链接。
<arel="external nofollow" href="#tips">VisittheUsefulTipsSection</a>或者,创建从另一个页面指向该文档中“有用的提示”部分的链接。
<arel="external nofollow" href="url/#tips">VisittheUsefulTipsSection</a>在上面的代码中,我们将#符号和锚名称添加到URL的末端,就可以直接链接到tips这个命名锚了。
参考资料:HTML的a标签-百度百科
关于html中a标签的用法的内容到此结束,希望对大家有所帮助。