用setAttribute方法就可以了,如:document.getElementById('d','123456')如果是动态添加标签的话:
var parent = document.getElementById(obj)//添加 div
var div = document.createElement("div")
//设置 div 属性,如 id
div.setAttribute("id", "newDiv")
div.innerHTML = "js 动态添加div"
parent.appendChild(div)
function addTarget(){var Sigma = document.getElementsByTagName('a')
for (var i = Sigma.length - 1i >= 0i--) {
Sigma[i].setAttribute("target","_blank")
}
}
window.onload = addTarget