论坛首页 Web前端技术论坛

CSS和JS去掉链接虚线框的多种方法

浏览 1827 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2014-08-12  

当我们点击链接后,链接周围会显示一个虚线框,那么怎么去掉这个虚线框呢?其实方法还挺多,用CSS就可以,但使用javaScript似乎也是一个好方法。

1. CSS方式去掉链接虚线框的方法: 
在IE下是使用html属性:hideFoucs,在HTML标签中加上hidefocus=”true” 属性即可,但这个属性是IE私有的,Firefox是不认的。前端框架示例

<a href="#" hidefocus="true" title="加了hidefocus" >加了hidefocus属性</a>

 

IE中用CSS处理:

a{noOutline:expression(this.onFocus=this.blur());}/* "onFocus" 注意大小写*/

 

Firefox的处理方法比较符合标准,只需要在CSS样式代码里设置a:focus{outline:none}皆可。接下来看一下MSIE和FF中统一处理的方法:

a{
outline:none; /*FF*/
noOutline:expression(this.onFocus=this.blur());/*IE*/
}

 

考虑性能优化,可参考以下代码:

a{outline:none;}
a:active{noOutline:expression(this.onFocus=this.blur());}
:focus{outline:0;}

 

2. 用js方式解决链接虚框的方法:前端框架示例

<script language="javascript">
$("a").bind("focus", function(){
if(this.blur){
this.blur();
}
});
</script>

 

论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics