DOM 요소 (id = "result")를 동적으로 추가/제거하려고합니다. 추가 기능은 정상적으로 작동하지만 제거한 후에도 요소가 페이지에 계속 표시됩니다.삭제 된 DOM 요소가 여전히 페이지에 나타납니다.
여기가 어떻게됩니까? 내가 도대체 뭘 잘못하고있는 겁니까?
<!DOCTYPE html>
<html>
<body>
<script>
function clearResult() {
if (document.getElementById("result") != null){
alert("remove #result");
$("#result").remove();
if (document.getElementById("result") != null) {
alert("#result still exists");
}
}
alert("Exiting clearResult");
}
function search() {
clearResult();
if (document.getElementById("result") == null) {
alert("add #result");
$('<table id="result"><tr>I am a table</tr></table>').appendTo('#ex');
}
}
</script>
<div>
<button id="search" onclick="search()" value="Send">Search</button>
</div>
<div id="ex">
@*Add result table here dynamically*@
</div>
</body>
</html>
TD는 어디에 있습니까? ? –