链接到某物的简单 div 标签。似乎无法弄清楚如何在 onclick 属性的不同选项卡中打开页面
var site_name = 'http://www.somesite.com'
var link = 'location.href='"+ site_name +"'
document.getElementById(div_name).setAttribute('onclick',link);
如果我使用的是 a 标签,我只会将目标设置为空白,否则我会迷路。
document.getElementById(divTagName).setAttribute('target','_blank');
最佳答案
document.getElementById(div_name).onclick = "window.open('" + site_name + "')";
关于css - 对于 <a> 标签设置它的属性 "target",javascript 中 onclick 的正确语法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7871464/