바이올린 here의 동작을 확인하십시오.동적으로 생성 된 페이지 요소 제거
$(document).ready(function() {
$('.tile').draggable();
$('.tile').on('dragstart', function() {
var numClones = $('.tile').length - 1
if (numClones > 0) {
//why can't I use fadeOut or empty here?
//make sure we don't remove the clone before it's made
$('.tile')[numClones].remove();
}
console.log(numClones);
var clone = $(this).clone();
clone.appendTo('body');
});
});
사용자는 드래그 이벤트에서 페이지 요소의 복제본을 만들 수 있습니다. 또한 이전 복제본을 제거합니다. 위의 주석 된 행에서 fadeOut
을 사용하여 페이지에서 div를 제거하려고 할 때 오류가 발생하는 이유는 무엇입니까? 그것은 jQuery 객체입니다.
$($('.tile')[numClones]).fadeOut();
JQuery와 객체 요소의 선택 일치의 배열로 위장 :이 시도 오류를 Object #<HTMLDivElement has no method fadeOut
없음; 없습니다 '$ ('. tile') [numClones]'는 DOM 노드 자체이며 jQuery 객체는 아닙니다. – Mathletics
원본 '.tile'도 제거해야합니까? – Mathletics