1

我一直在将 onclick 函数用于指向外部站点的链接:

<a href="http://outsidelink.net" target="_blank" onclick="return confirm('You will now be transfered to a third party website');">External Link</a> 

但我后来使用 jQuery 创建了一个类似“灯箱”的版本,通知用户他们要去另一个第三方网站。我不想每次都手动将每个链接复制到新的灯箱中。我宁愿从页面上的链接中复制 href 并将其添加到我的灯箱中的“继续”按钮。

我将如何获取这样的链接:

<a class="outsidelink" href="http://outsidelink.net">External Link</a> 

并将其添加到我有“CopiedLink”的灯箱中:

<div id="container">
<div id="textbox">
<a id="nothanks" href="#">Close</a>
<p>You are about to leave the site and go to a third party website.</p>
<a id="newlinkontheblock" href="CopiedLink" target="_blank">Continue</a>
</div>
</div>

我已经创建了创建灯箱的 .click 函数,我只是不知道如何从页面中获取链接并将其插入到新创建的灯箱中。有任何想法吗?

4

1 回答 1

3

像这样的事情应该这样做

$('a.outsidelink').click(function(e){
   // cancel default action of link so that it is not followed
   e.preventDefault();

   // open light box here


   // then
   $('#newlinkontheblock').attr('href', this.href);
});
于 2012-12-27T22:30:45.873 回答