如何从javascript文件复制href

如何从javascript文件复制href,javascript,jquery,hyperlink,href,Javascript,Jquery,Hyperlink,Href,我有一个链接 <a id="cartLink" href="https://site.foxycart.com/cart?cart=checkout" >Test</a> 正如您所看到的,我不能使用window.open()等。复制相同行为的最佳方法是什么,就像我单击href集的链接一样。类似的内容 $('#cartLink').live('click', function (e) { e.preventDefault();//This will preve

我有一个链接

<a id="cartLink" href="https://site.foxycart.com/cart?cart=checkout" >Test</a>
正如您所看到的,我不能使用window.open()等。复制相同行为的最佳方法是什么,就像我单击href集的链接一样。

类似的内容

 $('#cartLink').live('click', function (e) {
     e.preventDefault();//This will prevent the default behavior of the anchor.
     var count = $("#abc").text();
     var url = "https://site.foxycart.com/cart?cart=view&MyCount=" + count;
     window.location.href = url;//It will redirect to "url" in the current window.
 });

由于您选择的已选择id为#cartLink的任何元素,因此您可以从函数中将其称为$(this)

在var url=;写下以下内容:

$(this).attr('href', url);

$(this).attr('href', url);