자바스크립트 개체 복사

by 조쉬 posted Feb 27, 2014
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
<script language="javascript">
function rowCopy(){
var tbl = document.getElementById("tbl");
var node = {};
node = document.getElementById("tbl").firstChild.cloneNode(1);
document.getElementById("tbl").appendChild(node);
}
</script>
<a href="javascript:rowCopy();">복사</a>
<table border=1 id="tbl">
<tr>
<td bgcolor="#EEEEEE" style="border:'1 solid #777777'">아싸</td>
<td bgcolor="yellow" >거시기</td>
<td bgcolor="gray">잘될까</td>
<td bgcolor="green">잠안자고</td>
<td bgcolor="blue">했는데</td>
<td bgcolor="orange">잘되겠지?</td>
</tr>
</table>










<script language="javascript">
function origin(){
img1 = document.createElement('img');
img1.setAttribute('id', 'aaa');
img1.src = 'http://www.phpschool.com/images/level_point_info.gif';
document.body.appendChild(img1);
}
function copyn(){
img2 = img1.cloneNode(1);
document.body.appendChild(img2);
}
</script>

<html>
<body>
<a href="javascript:origin();">원본 생성</a><br>
<a href="javascript:copyn();">복사(계속 눌러보세요)</a>
</body>
</html>