【问题标题】:jquery target=_blank doesnt workjquery target=_blank 不起作用
【发布时间】:2011-03-23 20:48:32
【问题描述】:
我有这段代码:
$('.tool li a:first-child').each(function(){
$(this).after(' <a href="' + $(this).attr('href') + '" title="Open link in new tab"><img src="/img/icon-arrow.png" height="9" width="9" alt="Arrow Icon" target="_blank" /></a>');
});
因此,即使添加的图像使用 target=_blank 进行超链接,该链接也不会在新窗口中打开。
任何想法为什么浏览器无法识别?
-瑞恩
【问题讨论】:
标签:
jquery
attributes
target
【解决方案1】:
您需要在a 标签上添加target 属性,而不是img 标签。
$('.tool li a:first-child').each(function(){
$(this).after('<a href="' + $(this).attr('href') + '" title="Open link in new tab" target="_blank"><img src="/img/icon-arrow.png" height="9" width="9" alt="Arrow Icon" /></a>');
});
【解决方案2】:
target="_blank" 应该是锚标记的属性
替换:
$(this).after(' <a href="' + $(this).attr('href') + '" title="Open link in new tab"><img src="/img/icon-arrow.png" height="9" width="9" alt="Arrow Icon" target="_blank" /></a>');
与:
$(this).after(' <a href="' + $(this).attr('href') + '" target="_blank" title="Open link in new tab"><img src="/img/icon-arrow.png" height="9" width="9" alt="Arrow Icon" /></a>');