0
消失,我想有一個Add another field
按鈕創建每次按下按鈕時,文本字段<input type="text" name="pet">
。添加一個文本字段點擊按鈕使用javascript:除了文本字段中的所有內容上點擊
我目前有this code:
<html>
<head>
<script>
function add_field()
{
document.write('<input type="text" name="pet">');
};
</script>
</head>
<body>
<form name="input" method="get">
Favourite pets:<br>
<input type="text" name="pet">
<button type="button" onclick="add_field()">Add another field</button><br>
<input type="submit" value="Submit"><br>
</form>
</body>
</html>
但是,當我按下按鈕Add another field
我剛剛得到一個頁面,只有一個文本字段,我的所有其他內容消失。 如何在添加其他文本字段時仍保留其他html內容?