為什么創(chuàng)建一個子節(jié)點不行,用innerHTML才可以?。?/h1>
function?createa(url,text)
{??var?a=document.createElement("a");
???a.setAttribute("href","url");
???var?c=document.createTextNode("text");
???c.style.color="red";
???a.appendChild(c);
???main.appendChild(a);
}
function?createa(url,text) {??var?a=document.createElement("a"); ???a.setAttribute("href","url"); ???var?c=document.createTextNode("text"); ???c.style.color="red"; ???a.appendChild(c); ???main.appendChild(a); }
2018-08-05
去掉url和text的引號。
2018-08-04
因為text是a的文本而不是子節(jié)點