0
初學者在這裏。我已經嘗試了幾件事,並且遇到了類似問題的一些非常複雜的答案,但有沒有一種簡單的方法可以做到這一點?我設法讓它起作用,但它只是繼續覆蓋第一個條目。 謝謝。創建一個簡單的單場表單來構建香草中的名稱對象JavaScript
<h1>meal calculator</h1>
<div id='dinerForm'>
<label>What are the names of the diners?<input type='text' id='dinerName'></label>
<button type="button" onclick="buildDinerList()">Add to List</button>
</div>
<script>
//I'd like to be able to enter the names of the people in my party, ie., all diners
var dinerList = {};
function buildDinerList() {
dinerList.dinerName = document.getElementById('dinerName').value;
};
</script>
歡迎來到StackOverflow!這是有點不清楚你問什麼,一些例子輸出會有幫助。您將'dinerList'初始化爲一個對象,但將其命名並將其作爲列表進行討論。 –