我想知道如何輸出用戶想要在我的貨幣轉換器中轉換金額的不同貨幣符號?例如,如果我想在20歐元的新金額的最終產出中將20英鎊兌換成歐元,我怎樣才能得到歐元符號?最終的輸出只是數字,我想要一個貨幣符號在最終價值量輸出前面,我想知道如何爲輸出量的每種貨幣做到這一點。我正在從API導入實時匯率,因此,如何導入匯率但添加貨幣符號?如何在最終交換值中輸出貨幣符號?
JAVASCRIPT
// Fetch exchange rate data from api
$.getJSON("https://api.fixer.io/latest?base=ZAR", function(data) {
var currencies = [];
$.each(data.rates, function(currency, rate) {
// Currency options dropdown menu
currencies.push("<option id='" + currency.toLowerCase() + "' value='" + rate + "' >" + currency + "</option>");
});
$(".currency-list").append(currencies);
})
//Calculate and output the new amount
function exchangeCurrency() {
var amount = $(".amount").val();
var rateFrom = $(".currency-list")[0].value;
var rateTo = $(".currency-list")[1].value;
if (amount == undefined || rateFrom == "--Select--" || rateTo == "--Select--") {
$(".results").html("0");
} else {
$(".results").html((amount * (rateTo * (1/rateFrom))).toFixed(2));
}
}
它不需要太多[*搜索*](https://www.google.com.au/search?q=HTML+entities+currency+symbol&rls=com.microsoft:en-us&ie=UTF -8&oe = UTF-8&startIndex =&startPage = 1&safe = active&gfe_rd = cr&ei = cSgeWbLfDOzDXvCZgYAC&gws_rd = ssl)查找貨幣符號的HTML實體列表,例如[*這裏*](https://websitebuilders.com/tools/html-codes/currency/)。 – RobG