[英]Remove and then add child node
I have a table that need to be hidden on page load and then shown after login So i figured out how to remove the table on login but don't have a clue how to return it 我有一个需要在页面加载时隐藏的表,然后在登录后显示,所以我想出了如何在登录时删除该表,但是不知道如何返回该表
<table class="showAfter">
<tr>
<th></th>
</tr>
</table>
function restart(){
var removeTable = document.querySelector('.showAfter');
while (removeTable.hasChildNodes()) {
removeTable.removeChild(removeTable.firstChild);
}
}
function restore(){
var addTable = document.querySelector('.showAfter');
while (!addTable.hasChildNodes()) {
append?
}
}
Thanks for the help 谢谢您的帮助
Here's a super cheap way to do the same. 这是一种非常便宜的方法。
<table class="showAfter">
<tr>
<th></th>
</tr>
</table>
var savedTable = "": // establish var on the window scope so both functions can access it.
function restart(){
var removeTable = document.querySelector('.showAfter');
savedTable = removeTable.innerHTML;
removeTable.innerHTML = "";
// while (removeTable.hasChildNodes()) {
// removeTable.removeChild(removeTable.firstChild);
// }
}
function restore(){
var addTable = document.querySelector('.showAfter');
addTable.innerHTML += savedTable;
savedTable = "";
// while (!addTable.hasChildNodes()) {
// append?
// }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.