javascript - 使用下拉菜单更改货币
问题描述
所以我想知道有没有办法通过使用下拉选择按钮来改变货币?
例子 :
- 印尼盾 (RP) 至 美元 (USD)
已经尝试使用 if-else 并且失败了我需要使用 jquery/javascript 吗?
我试试这个但还是不明白
selector = document.getElementById("currencySelector");
var
currencyElements = document.getElementsByClassName("currency");
var
usdChangeRate = {
AUD: 1.0490, // 1AUD = 1.0490 USD
EUR: 1.4407, // 1EUR = 1.4407 USD
GBP: 1.6424,
USD: 1.0
};
selector.onchange = function () {
var toCurrency = selector.value.toUpperCase();
for (var i=0,l=currencyElements.length; i<l; ++i) {
var el = currencyElements[i];
var fromCurrency = el.getAttribute("data-currencyName").toUpperCase();
if (fromCurrency in usdChangeRate) {
var // currency change to usd
fromCurrencyToUsdAmount = parseFloat(el.innerHTML) * usdChangeRate[fromCurrency];
var // change to currency unit selected
toCurrenyAmount = fromCurrencyToUsdAmount / usdChangeRate[toCurrency];
el.innerHTML = toCurrenyAmount + "<span>" + toCurrency.toUpperCase() + "</span>";
el.setAttribute("data-currencyName",toCurrency);
}
}
};
我的下拉菜单:
<select name="matauang" class="form-control" onchange = "changecurrency()" id="matauang">
<option value="null" selected disabled>Choose</option>
<?php foreach($payment as $pay) : ?>
<option value="<?php echo $pay["kurs"]; ?>"><?php echo $pay["kurs"]; ?></option>
<?php endforeach; ?>
</select>
我的桌子:
<table class="table table-fixed table-bordered table-hover" style="width:100%;" id="tebal">
<thead>
<tr>
<th scope="col">Jumlah/Quantity </th>
<th scope="col">Unit Price </th>
<th scope="col">Sub Total </th>
</tr>
</thead>
<tbody>
foreach ($query as $kiki) : ?>
<tr class="table-row">
<td><?php echo $kiki["qty_op"]; ?></td>
<td><?php echo $kiki["price"]; ?></td>
<td class="calc"><?php $total = $kiki["qty_op"]*$kiki["price"]; echo $total; ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
是否有任何方法可以将表Sub Total
值更改为美元?因为我制作的格式是,我想通过从下拉列表中选择Rupiah (RP)
来更改货币。如果我必须使用请告诉我,因为我真的很陌生Rp
Usd
js
js
解决方案
推荐阅读
- java - 数组中的 Java 随机数
- sql - 如何在sql中搜索列表中的字符串?
- django - 序列化多个对象时删除特定实例(many=True),其中一个有错误
- .net - React + SignalR 服务类的最佳方式是什么?
- python - 神经分割网络根据测试批量大小给出不同的输出
- r - 如何在 R 中使用 HCPC 和 FactoMineR 预测新数据的集群
- python - 从 google admin sdk 获取状态码
- sqlite - 房间实体的数据类
- r - 如何在 R 中编写条件语句
- erlang - 在 erlang 中访问之前,是否有任何方法可以检查 xml 中的元素?