去掉点击链接后的虚线框

点击一个超链接后默认会有一个虚线框,有时候要求去掉它。

firefox及标准浏览器下可以用css属性outline:

outline:none;/*0也可以*/

IE下如下实现(据说过多使用效率低):

a {
   blr:expression(this.onFocus=this.blur());
} 

此外还可以使用 hidefocus 属性。

webkit内核浏览器(Safari/Chrome)中点击链接后不会有虚线框,这应该是默认样式的问题。如果想让其和IE/Firefox一样点击后留下虚线框可加入以下:

a:visited {
	outline:1px dotted gray;
}

最早期,用一种很蛋疼的方法,获取焦点的事件中又失去焦点。

<a onfocus="this.blur()" href="javascript:void 0">设置主题</a>

相关:

http://24ways.org/2009/dont-lose-your-focus

http://people.opera.com/patrickl/experiments/keyboard/test

http://www.zhihu.com/question/20144196

原文地址:https://www.cnblogs.com/snandy/p/3183575.html