我有一個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