我建了兩個按鈕,這個值(「+」和「 - 」) 當我點擊「+」它會創建一個文本和組合框, 我想知道如何與刪除「 - 」?按鈕(由只有JavaScript)如何通過按鈕刪除對象?
下面的代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>create and delete</title>
<script type="text/javascript">
/*this function creates text box and combo box*/
function cre()
{var t=document.createElement('select');
var form=document.getElementById('theForm');
var label = document.createElement('label');
var textbox = document.createElement('input');
form.appendChild(t);
form.appendChild(textbox);}
function del()
/*{delete t,form,label,textbox;}*/
</script>
</head>
<body>
<form id='theForm'>
<input type="button" value="+" onclick="cre()" />
<input type="button" value="-" onclick="del()" />
</form>
</body>
</html>
https://developer.mozilla.org/en-US/docs/DOM/Node.removeChild – 2013-05-08 05:40:20
看看[這裏](http://stackoverflow.com/questions/ 3387427/JavaScript的刪除元素,通過-ID) – quickshiftin 2013-05-08 05:41:22
你爲什麼不試試jQuery的?這是很容易 – Shin 2013-05-08 06:11:40