试试这个:
var elem = document.getElementById("dark"); // #dark if (elem && elem.nodeName == "TD" && elem.height == 260) { // td#dark[] var newElem = document.createElement("a"); newElem.href = "http://www.example.com"; elem.appendChild(newElem); }
对于在多个元素上使用相同ID的非标准文档:
var elems = document.getElementsByTagName("td"); for (var i=0; i