2013-04-03 77 views
1

這是第2部分我剛纔的問題。這裏是標記:傳遞數據和鏈接屬性,以新的div

HTML

<a data-message="my message" href="www.site.com">click here</a> 

<div class="new-window"> 
    <p>(my message)</p> 
    <a href="LINK-GOES-HERE">proceed</a> 
</div> 

JS

$('a[data-message]').click(function(){ 
    $('.new-window').fadeIn(300); 
    $('.new-window p').text($(this).data('message')); 
    return false; 
}); 

由於有頁面上的鏈接很少,我想要一個自定義的div窗口(而不是標準的alert)來顯示消息和url傳遞給新窗口。有沒有辦法將所選鏈接的URL傳遞給新窗口?

感謝

回答

1

後:

$('.new-window p').text($(this).data('message')); 

地址:

$('.new-window a').attr('href', $(this).attr('href')); 
+1

謝謝,你真棒:) – Josh

1
$('.new-window p').text(this.href); 
1

這可能幫助:

$('a[data-message]').click(function(){ 
     console.log($(this).attr('href')); 
     $('.new-window').fadeIn(300); 
     $('.new-window p').text($(this).data('message')); 
     return false; 
    }); 
+1

除了日e'console.log'你從OP的代碼中改變了什麼? – j08691

+0

就是這樣我不會去做所有的工作。 – matpol