簡體   English   中英

如何通過使用node.remove()撤消已刪除的標記,或者是否可以撤消此操作?

[英]how to undo the removed tages by using node.remove() .or is it possible to undo this?

<html>

<body>


<div id="div1">

<p id="p1">This is a paragraph.</p>

<p id="p2">This is another paragraph.</p>

</div>

<script>

var para = document.createElement("h1");

var node = document.createTextNode("<h2>This is new.<h2>");

para.appendChild(node);

var element = document.getElementById("div1");

element.appendChild(para);

element.remove();//is it possible to get "element" variable back 

</script>

</body>
</html>

是的。

element.style.display=none;

可以通過單擊按鈕來撤消

<button onclick="document.getElementById("div1").style.display=block;">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM