将 href 数据属性添加到目标为空白的 div
Add href data attribute to a div with target blank
我尝试使用数据属性在 div 上应用 href 属性
因为我不能在我的案例中使用 A 标签。
它工作正常,但我正在尝试添加另一个数据属性以便在目标空白中打开 link
这是我的代码
$('.artist-box').each(function(){
var aTag = $(this).attr('href');
$(this).attr('data-href',aTag);
$("[data-href]").click(function() {
window.location.href = $(this).attr("data-href");
return false;
});
})
有人可以帮忙吗?
谢谢
使用window.open代替window.location
$('.artist-box').each(function(){
var aTag = $(this).attr('href');
$(this).attr('data-href',aTag);
$("[data-href]").click(function() {
window.open($(this).attr("data-href"),'_blank');
return false;
});
})
我尝试使用数据属性在 div 上应用 href 属性 因为我不能在我的案例中使用 A 标签。 它工作正常,但我正在尝试添加另一个数据属性以便在目标空白中打开 link 这是我的代码
$('.artist-box').each(function(){
var aTag = $(this).attr('href');
$(this).attr('data-href',aTag);
$("[data-href]").click(function() {
window.location.href = $(this).attr("data-href");
return false;
});
})
有人可以帮忙吗? 谢谢
使用window.open代替window.location
$('.artist-box').each(function(){
var aTag = $(this).attr('href');
$(this).attr('data-href',aTag);
$("[data-href]").click(function() {
window.open($(this).attr("data-href"),'_blank');
return false;
});
})