2011-07-27 98 views
1

我需要在用戶點擊鏈接時顯示一些文本,然後在點擊鏈接後刪除鏈接。如何刪除鏈接?

這裏舉例:http://jsfiddle.net/HCAfz/2/

如何刪除從頁面被點擊並保持上述行爲的聯繫,與隱藏的div被顯示?

+0

將要刪除點擊時出現'a'標籤?還有內容? – PeeHaa

回答

1

要c ompletely刪除鏈接做:

$('a.yourLink').click(function(event) { 
    $(this).next('.hiddenDiv').show(); 
    window.open(this.href, '_blank'); 
    $(this).remove(); 

    return false; 
}); 

要隱藏的鏈接做到:

$('a.yourLink').click(function(event) { 
    $(this).next('.hiddenDiv').show(); 
    window.open(this.href, '_blank'); 
    $(this).hide(); 

    return false; 
}); 

注意,我在event.preventDefault();代替做return false;event.stopPropagation();,因爲它是一樣的

1

你需要更好地解釋自己,但最簡單的情況下加入這一行:

$(this).hide(); 
1

我想你需要這個

$('a.yourLink').click(function(e) { 
     e.preventDefault(); 
     $(this).hide().next('.hiddenDiv').show(); 
     window.open(this.href, '_blank'); 
});