2016-12-16 48 views
0

我想使用下面的代碼來隱藏鏈接上的<a>標籤鏈接時的URL。在它下面設置一個<a>標籤(#no-link),我希望它適用於所有的<a>標籤。任何人都可以幫忙嗎?當鼠標懸停在<a>以上時隱藏地址標籤

$(document).ready(function() { 
    setTimeout(function() { 
     $('a[href]#no-link').each(function() { 
      var href = this.href; 

      $(this).removeAttr('href').css('cursor', 'pointer').click(function() { 
       if (href.toLowerCase().indexOf("#") >= 0) { 

       } else { 
        window.open(href, '_blank'); 
       } 
      }); 
     }); 
    }, 500); 
}); 
+2

這樣做有什麼實際目的是什麼?因爲找到實際的URL仍然很簡單。充其量只會傷害可用性。 – vlaz

+0

我在頁面上有很多照片鏈接到另一個頁面。當網頁滾動時,它看起來很亂。 – Eddy

+0

另外,爲什麼如果你定位的元素被描述爲一個'id',爲什麼會有'each':'$('a [href]#no-link')'('具有href屬性和id爲no的元素-鏈接')? – somethinghere

回答

1

這應該工作,現在你選擇所有的錨元素。

$(document).ready(function() { 
setTimeout(function() { 

    $('a').each(function() { 
     var href = this.href; 

     $(this).removeAttr('href').css('cursor', 'pointer').click(function() { 
      if (href.toLowerCase().indexOf("#") >= 0) { 

      } else { 
       window.open(href, '_blank'); 
      } 
     }); 
    }); 

}, 500); 
}); 
+0

不是所問的問題。一個問題,但不是問題。 – somethinghere

0

我不知道這個答案,我只是試圖隱藏錨標記,當它盤旋

<script src="http://code.jquery.com/jquery-latest.min.js" 
      type="text/javascript"></script> 
    <a class="no-link" href="samp1.html">samp1</a> 
    <a class="no-link" href="samp2.html">samp2</a> 
    <script> 
    $(document).ready(function() { 
    $('.no-link').hover(function(){ 
    $(this).hide(); 
    }) 

    }); 
    </script> 
相關問題