iT邦幫忙

2023 iThome 鐵人賽

DAY 15
0

之前剛好坐了一個幣值轉換的網頁 分享一下部分CODE


currencySelect.addEventListener("change", function () {
    convertToSelect.innerHTML = "";


    const originalCurrency = currencySelect.value;


    for (const currency in exchangeRates[originalCurrency]) {
        const option = document.createElement("option");
        option.value = currency;
        option.textContent = currency;
        convertToSelect.appendChild(option);
    }
});


convertButton.addEventListener("click", function () {
    const originalCurrency = currencySelect.value;
    const convertToCurrency = convertToSelect.value;
    const amount = parseFloat(document.getElementById("price-input").value);

    // 貨幣轉換
    const rate = 1 / exchangeRates[convertToCurrency][originalCurrency]; // 取倒数
    const converted = amount * rate;

    convertedAmount.textContent = `${amount} ${originalCurrency} = ${converted.toFixed(2)} ${convertToCurrency}`;
});



上一篇
<DAY14>
下一篇
<DAY16>Python的日誌記錄 X Logging
系列文
擱淺中掙扎29
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言