我需要在用戶點擊鏈接時顯示一些文本,然後在點擊鏈接後刪除鏈接。如何刪除鏈接?
這裏舉例:http://jsfiddle.net/HCAfz/2/
如何刪除從頁面被點擊並保持上述行爲的聯繫,與隱藏的div被顯示?
我需要在用戶點擊鏈接時顯示一些文本,然後在點擊鏈接後刪除鏈接。如何刪除鏈接?
這裏舉例:http://jsfiddle.net/HCAfz/2/
如何刪除從頁面被點擊並保持上述行爲的聯繫,與隱藏的div被顯示?
要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();
,因爲它是一樣的
'.hide()'會在這裏更有意義,或'.remove' –
你說得對。舊的光禿禿的骨頭DOM習慣很難消退。 :P –
你需要更好地解釋自己,但最簡單的情況下加入這一行:
$(this).hide();
我想你需要這個
$('a.yourLink').click(function(e) {
e.preventDefault();
$(this).hide().next('.hiddenDiv').show();
window.open(this.href, '_blank');
});
將要刪除點擊時出現'a'標籤?還有內容? – PeeHaa