當按鈕被點擊時,文本「現在我在這裏......」應該消失,而不是按鈕本身。爲什麼按鈕消失?
<div id="alpha">Now I'm here...</div>
<button type="button" onclick="remove()">Remove</button>
<script>
function remove()
{
var element = document.getElementById("alpha");
element.parentNode.removeChild(element);
}
/*function add()
{
var ele = document.createElement("p");
var text = document.createTextNode("This is new text");
ele.appendChild(text);
var location = document.getElementById("alpha");
location.appendChild(ele);
}*/
</script>
的可能重複[如何清除使用javascript一個div的內容?](http://stackoverflow.com/questions/3450593/how-to-clear-the-content-of-a-div-using- javascript) –
這是一個很好的問題@Celeritas。我讓你成爲一個小提琴:http://jsfiddle.net/5x84v/ – dgp
如果你去這裏http://jsfiddle.net/5x84v/1/,似乎刪除函數根本沒有被調用。嘗試重命名爲「deleteRow」或類似的東西,看看是否有幫助 – FamiliarPie