CSS和JS去掉連結虛線框的多種方法

來源:互聯網
上載者:User

標籤:jquery   ui   web前端   前端   架構   

當我們點選連結後,連結周圍會顯示一個虛線框,那麼怎麼去掉這個虛線框呢?其實方法還挺多,用CSS就可以,但使用javaScript似乎也是一個好方法。

1. CSS方式去掉連結虛線框的方法: 
在IE下是使用html屬性:hideFoucs,在HTML標籤中加上hidefocus=”true” 屬性即可,但這個屬性是IE私人的,Firefox是不認的。前端架構樣本

.代碼  
  1. <a href="#" hidefocus="true" title="加了hidefocus" >加了hidefocus屬性</a>  

 

IE中用CSS處理:

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

 

Firefox的處理方法比較符合標準,只需要在CSS樣式代碼裡設定a:focus{outline:none}皆可。接下來看一下MSIE和FF中統一處理的方法:

.代碼  
  1. a{  
  2. outline:none; /*FF*/  
  3. noOutline:expression(this.onFocus=this.blur());/*IE*/  
  4. }  

 

考慮效能最佳化,可參考以下代碼:

.代碼  
  1. a{outline:none;}  
  2. a:active{noOutline:expression(this.onFocus=this.blur());}  
  3. :focus{outline:0;}  

 

2. 用js方式解決連結虛框的方法:前端架構樣本

.代碼  
  1. <script language="javascript">  
  2. $("a").bind("focus", function(){  
  3. if(this.blur){  
  4. this.blur();  
  5. }  
  6. });  
  7. </script>  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.