添加a標(biāo)簽 不成功 咋回事
var node_td3 = document.createElement("td");
? ? ? ? ? ? ? var node_a = document.createElement("a");
? ? ? // ?
? ? ? ? ?node_a.innerHTML="刪除";
? ? ? ? ? node_a.setAttribute("href") = "http://www.baidu.com";
? ? ? ? ? node_td3.appendChild(node_a);
2016-06-17
抱歉,手誤,第二行應(yīng)該是這樣:
2016-06-17
題注是想在td標(biāo)簽內(nèi)添加標(biāo)簽屬性吧,首先添加td屬性不需要另外創(chuàng)建一個(gè)element,而且setAttribute()的語(yǔ)法也錯(cuò)了,應(yīng)該是setAttribute("屬性","值")這種形式;
改成:
var?node_td3?=?document.createElement("td"); node_td3.innerHTML="<a?;2016-06-15
首先在td里怎么加a標(biāo)簽?zāi)兀强盏?,因?yàn)槟愕膖d都是新創(chuàng)建的,他應(yīng)該加在其他節(jié)點(diǎn)上,才能在他上面加呀,比如你可以var node_td3 = document.body;,然后向body中間加上a標(biāo)簽
方便的可一直接node_td3.innerHTML=‘<a href="
當(dāng)然你的setAttribute不對(duì)
應(yīng)該是node_a.setAttribute("href","http://www.baidu.com");