更新时间:2023-12-04 23:47:40
好的我解决了。我的代码中有一些错误。它现在正在工作。
ok I solved it. There was some error in my code. Its working now.
<html>
<head>
<script type="text/javascript">
function add() {
var i = document.getElementById( 'old' );
var d = document.createElement( 'div' );
d.id = "new1";
d.innerHTML = i.innerHTML ;
var p = document.getElementById('new');
p.appendChild(d);
}
function removeLocation() {
var d = document.getElementById( 'new1' );
var p = document.getElementById('new');
p.removeChild(d);
}
</script>
</head>
<body>
<div id="old">
Content of old div
</div>
<hr/>
<div id="new">
</div>
<hr/>
<button onclick="add();">Add</button><br>
<button onclick="removeLocation();">Remove</button>
</body>
</html>