JS怎样使用appendChild增加一个<a target="_black" href="http://baidu.com">点我进入百度</a>

来源:百度知道 编辑:UC知道 时间:2024/05/08 09:32:17
并且使用完之后要关闭这个资源.
要在<table><tr><td id="show"></td></tr></table>

要在show里增加这个超链接。

var a = document.createElement('a');
a.target = '_black';
a.href = 'http://baidu.com';
a.appendChild(document.createTextNode('点我进入'));
document.getElementById('show').appendChild(a);

document.getElementById('show').innerHTML="<a target=\"_black\" href=\"http://baidu.com\">点我进入百度</a>";

比你用appendChild省事