2012-06-05 92 views
0

我正在爲我的圖像庫使用lytebox。除非用戶在圖像上懸停,否則它會很好用,瀏覽器上會顯示帶有html標籤的文本。將鼠標懸停在圖像上時刪除圖像標題

例如:

<h1>This is the first image </h1> 
<p>The image desc<p> 

我需要爲我的圖片庫的title屬性,但不希望它顯示在用戶hovesr圖像。那可能嗎?謝謝您的幫助。

+0

可以將它發佈在jsfiddle或演示您的網站? – Dips

+0

你可以使用css隱藏懸停效果,但對於標題你可能需要更改jquery。 – Dips

+0

爲什麼你不使用alt標籤而不是標題呢? –

回答

4
var imgTitle; 

$("img").hover(function(){ 
    imgTitle = $(this).attr("title"); 
    $(this).removeAttr("title"); 
}, function(){ 
    $(this).attr("title", imgTitle); 
}); 
+0

我想你打敗了我2秒。 +1。 – lucuma

+0

thx尋求幫助。 jsfiddle示例+1的+1 – FlyingCat

2

我認爲你必須做這樣的事情:

$('#slideshow img').hover(function() { 
    $(this).data('title', $(this).attr('title')); 
    $(this).attr('title', ''); 
}, function() { 
    $(this).attr('title', $(this).data('title')); 
});​ 

演示:http://jsfiddle.net/lucuma/cX5MD/

你不會看到在IMG的標題,但如果你檢查他們,你會看到他們仍然在那裏。

您也可以使用jQuery removeAttrattr而不是將其設置爲空字符串。

+0

ty。 :) – FlyingCat