我有一个WP博客页面,显示使用类别简码近期帖子 在该页面上,我有一个链接列表,指向他们的帖子。 我不能编辑链接添加id或类给他们,所以我手动使用div来包装短代码和一个JavaScript,使链接打开到新标签点击后,有没有办法我可以打开所有的链接到新标签打开单击? (请记住,我不能编辑LINKS) 这里是我的代码自动点击Div ID中的所有链接
<!--- i cant edit the links below ----->
<div id="boss" class="boss">
<a href="http://example.com/example-1" title="Example 1">Example 1</a>
<a href="http://example.com/example-1" title="Example 1">Example 2</a>
<a href="http://example.com/example-1" title="Example 1">Example 3</a>
<a href="http://example.com/example-1" title="Example 1">Example 4</a>
</div>
JAVASCRIPT
<script type="text/javascript">
window.onload = function(){
var a = document.getElementById('boss').getElementsByTagName('a');
for (var i=0; i<a.length; i++){
a[i].setAttribute('target', '_blank');
}
}
</script>
我试图在点击
<div onclick="boss();">Something To Click On</div>
其加载的所有链接到他们的新标签不工作,任何帮助PLS?
请告诉我老板的功能是什么样子? – Kilmazing