我的提示框不起作用?自從我把元素的東西放在那裏不工作。用提示創建一個網頁
我需要提示框,以便我可以輸入信息,然後該信息自動進入表格,然後通過在表格的行中自動讀取最大金額$。我不是100%的js編碼,所以不要笑,如果它是一個簡單的修復(這是簡單的事情,讓我)。
這是我的代碼,我不知道我做錯了
「我的表是在頭」
function money(){
this.currency = "";
this.amount = "";
this.exchangeRate = "";
this.ausDollars = "";
tbody = document.getElementsByTagName('tbody')[0];
for (var i = 0; i <= 3; i++)
trElement = document.createElement('tr');
tbody.appendChild(trElement);
// Read the 3 letter currency abbreviation entered
currency = prompt('Please enter a 3-letter currency abbreviation', +i, "");
// If the input data is invalid ask the user to re-enter it
while (currency.length != 3) {
currency = prompt('Currency abbreviation was not entered', "");
currency = parseFloat(currency);
}
currencyTH = document.createElement('th');
currencyText = document.createTextNode(currency);
currencyTH.appendChild(currencyText);
trElement.appendChild(currencyTH);
// Read the amount and convert it to entered currency
amount = prompt('Please enter an amount of money in that currency', +i, "");
// If the input data is invalid ask the user to re-enter it
while (isNaN(amount) || amount < 0) {
amount = prompt('An amount of money was not entered')
amount = parseFloat(amount);
}
amountTH = document.createElement('th');
amountText = document.createTextNode(amount);
amountTH.appendChild(amountText);
trElement.appendChild(amountTH);
exchangeRateTH = document.createElement('th');
exchangeRateText = document.createTextNode(exchangeRate);
exchangeRateTH.appendChild(exchangeRateText);
trElement.appendChild(exchangeRateTH);
}
你有一個for循環創建trElement 4次。但只做最後一件事。我假設你的for循環想要更像'for(var i = 0; i <= 3; i ++){'注意大括號,你當然需要在for循環結尾使用另一個大括號。 – Keith
因此,我有tbody.appendChild(trElement)後的大括號;喜歡這個? tbody = document.getElementsByTagName('tbody')[0]; (var i = 0; i <= 3; i ++){ \t trElement = document。的createElement( 'TR'); \t tbody.appendChild(trElement); \t} – Claire