2011-03-23 43 views
0

我有这样一段代码:jQuery的目标= _blank不工作

$('.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>'); 
    }); 

因此,即使是添加了图像与目标超链接= _blank,链接不会在新窗口中打开。

任何想法为什么浏览器不承认?

-Ryan

回答

3

您需要添加对a标签,而不是img标签target属性。

$('.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>'); 
}); 
+0

笑......如果只是所有的问题都这很容易解决:) – NightHawk 2011-03-23 20:54:57

1

目标= “_空白” 应该是锚标记属性

替换:

$(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>');