如何用原生JS编写一个长尾词包含的汇率转换器代码实例?
- 内容介绍
- 文章标签
- 相关推荐
本文共计184个文字,预计阅读时间需要1分钟。
Exchange Rate Calculator
代码如下
html代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta api.exchangerate-api.com/v4/latest/${currency_one}`) .then(res => res.json()) .then(data => { const rate = data.rates[currency_two]; rateEl.innerText = `1 ${currency_one} = ${rate} ${currency_two}`; amountEl_two.value = (amountEl_one.value * rate).toFixed(2); }); }; // 得到汇率 function getData() { let currency_one = currencyEl_one.value; let currency_two = currencyEl_two.value; fetch(`api.exchangerate-api.com/v4/latest/${currency_one}`) .then(res => res.json()) .then(data => { const rate = data.rates[currency_two]; rateEl.innerText = `1 ${currency_one} = ${rate} ${currency_two}`; amountEl_two.value = (amountEl_one.value * rate).toFixed(2); }); }
运行效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。
本文共计184个文字,预计阅读时间需要1分钟。
Exchange Rate Calculator
代码如下
html代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta api.exchangerate-api.com/v4/latest/${currency_one}`) .then(res => res.json()) .then(data => { const rate = data.rates[currency_two]; rateEl.innerText = `1 ${currency_one} = ${rate} ${currency_two}`; amountEl_two.value = (amountEl_one.value * rate).toFixed(2); }); }; // 得到汇率 function getData() { let currency_one = currencyEl_one.value; let currency_two = currencyEl_two.value; fetch(`api.exchangerate-api.com/v4/latest/${currency_one}`) .then(res => res.json()) .then(data => { const rate = data.rates[currency_two]; rateEl.innerText = `1 ${currency_one} = ${rate} ${currency_two}`; amountEl_two.value = (amountEl_one.value * rate).toFixed(2); }); }
运行效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

