-4
<script>
function create()
{
var div = document.createElement('div');
div.textContent = document.getElementById('text').value;
div.setAttribute('class', 'note');
document.body.appendChild(div);
div.style.background="yellow";
div.style.Width="300px";
div.style.height="100px";
if(document.getElementById('text').value=="")
{
div.parentNode.removeChild(div);
alert("Plz Put Some text");
}
}
</script>
<body>
<input type="button" onclick="create()" value="create"/>
<input type="text" id="text" />
</body>
每次加載頁面時,都會得到新的副本。如果刷新,則對DOM所做的更改將不會保存。 –