2012-01-31 7 views
0

나는 html tr 및 th의 복제를 원하지만 outer thead/thead 요소는 캡처하지 않습니다.JQuery는 thead 테이블의 각 tr 만 복제합니다.

<thead id="justCloneTR"> // don't clone 
<tr id="Vehicle_1">  // clone 
    <th>1</th>    // clone 
    <th>2</th>    // clone 
</tr>     // clone 
</thead>     // don't clone 

<div id="putCloneHere"></div> 

JS

$('#justCloneTR').clone('tr').appendTo('#putCloneHere'); 
+1

['$ Vehicle_1 '] .clone();'] (http://api.jquery.com/clone) –

+0

젠장! 그거 쉽지. 감사합니다 롭! – user1040259

답변

4

당신이 tr-id이있는 경우 다음 방금이를 사용할 수 있습니다.

$('#Vehicle_1').clone(); 

.clone() 참조 : http://api.jquery.com/clone/

기억이 DOM에 추가하기 전에 동일한 ID로 두 요소가 없어야합니다 때문에 복제 된 요소의 ID를 변경해야 복제 후.

시도해보십시오.

var id = 'Vehicle_' + parseInt($('#Vehicle_1').attr('id').match(/\d+/g), 10) + 1; 
$('#Vehicle_1').clone().attr('id', id).appendTo('#putCloneHere'); 
+0

감사합니다, 완벽하게 작동합니다! – user1040259

관련 문제