- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我不需要使用 Yahoo Finance api 等。只需将数字乘以固定数量即可。
See codepen .下拉功能没有实现,我想先把交换下来。我知道这只是一个开始,但如何继续下去呢?这显然需要解决几个问题:
你能给我一些指示,我应该如何继续吗?
$(document).ready(function() {
// $('select').material_select();
$('.caret').text(" ");
//here starts my attempt for the exchange
var price = $(".price").text().replace("$", "");
var convertedToNumber = parseFloat(price);
var eurPrice = convertedToNumber / 1.18;
$(".price").text(eurPrice);
});
input.select-dropdown {
color: #26a69a;
}
.caret {
background:url("http://svgshare.com/i/3Bc.svg") no-repeat 90% 50%;
width:20px;
height:auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="row">
<div class="input-field col s1">
<select>
<option value="1" selected>USD</option>
<option value="2">EUR</option>
</select>
<label>Currency</label>
</div>
</div>
<ul class="currencies">
<li class="price">$1500</li>
<li class="price">$2000</li>
<li class="price">$342</li>
</ul>
最佳答案
您正在寻找的称为数据绑定(bind),有很多库和东西可以为您提供它。
我会假设你不知道我在说什么,我只会向你解释基本思想是什么。
你有一组数据,在你的例子中是价格。
var prices = [
1500,
2000,
342
];
然后你有你的货币汇率对象
var rates = {
USD: 1, // obviously
EUR: 0.86
}
现在,每次货币更改时,您都会重新计算价格并更新每次出现的情况。
function updatePrices(rate) {
var elements = document.getElementsByClassName("price");
prices.forEach((price, index) => {
elements[index].innerHTML = price * rate
});
}
document.getElementById("selector").onchange = function() {
updatePrices(rates[this.value]);
}
并且最初也调用它。
updatePrices(rates.USD);
现在显然这是一种非常愚蠢的数据绑定(bind)方式,使用数组索引和类名,但这是它背后的基本思想。
至于货币符号,将它们包括在内通常不是一个好主意,因为实际上很少有货币具有它们,但想法是一样的。
var prices = [
1500,
2000,
342
];
var rates = {
USD: 1, // obviously
EUR: 0.86
}
function updatePrices(rate) {
var elements = document.getElementsByClassName("price");
prices.forEach((price, index) => {
elements[index].innerHTML = price * rate
});
}
document.getElementById("selector").onchange = function() {
updatePrices(rates[this.value]);
}
updatePrices(rates.USD);
<div class="row">
<div class="input-field col s1">
<select id="selector">
<option value="USD" selected>USD</option>
<option value="EUR">EUR</option>
</select>
<label>Currency</label>
</div>
</div>
<ul class="currencies">
<li class="price"></li>
<li class="price"></li>
<li class="price"></li>
</ul>
关于javascript - 使用 jquery 将页面上的所有价格从一种货币更改为另一种货币?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46453085/
条件: 我们需要我们 Magento 网站的默认显示货币是美元,Paypal(基础货币)也需要是美元(因为我们需要客户以美元支付)。 我们的 Fedex a/c 是在新加坡开设的,结果发现运费是以新加
根据 currency_str 和 created_date_time 合并两个数据帧(xrate 和 df)时遇到问题 display(xrate.info()) Int64Index: 1611
我必须匹配像 这样的值 € 6.483,00 或类似的值 18,50% 或者,再次, +65,86 % 在我起草的 Javascript 函数中: function(s) { return /^
我正在尝试将货币金额解析并存储为 BigDecimal 值。我得到了相关货币的区域设置,在大多数情况下它工作正常,但当货币是哥斯达黎加科朗时我得到了意想不到的结果。 我的哥斯达黎加客户告诉我,典型的货
在当前版本的 Excel(Office 365/2019 年 2 月)中获得近似每日外汇汇率的最简单的免费方法是什么。 我对历史数据不感兴趣,我只想要从货币 X 到货币 Y 的最后已知日汇率,并且只在
我在 spree 时遇到了麻烦,不知道如何处理。 我无法更改主要货币。 我该怎么做? 最佳答案 它在 Spree 2.0.0 中更容易,而且显然它也可以在以前的 spree 版本中工作。 转到您的 c
在我的网络应用程序中,我有一个名为“预算”的输入字段,用户可以在其中输入项目的建议预算。我需要创建一个屏蔽输入,以便在用户在输入字段中输入时自动将输入的金额转换为以下格式: 1000 10 000 1
我正在从数据库返回一个字符串,但由于数据库的编码方式,一些英镑符号 (£) 被问号取代。我想恢复井号,但不替换字符串中真正的问号。我已经设法编写了一个正则表达式来测试问号后跟数字的组合,但我不确定如何
我在使用亚马逊销售 API 时遇到问题。我在 amazon.co.uk 有一个帐户,可以正常发送产品。我在 amazon.de 有一个新帐户,除了货币外,一切都很好。 我有一个零售价为 10 英镑 (
Pharo 有什么方法可以将数字转换为单词。 例如:1200 = 一千二百而已。 实现起来并不难,只是想知道。 最佳答案 Integer>>asWords会这样做。 1200 asWords返回 'o
我有一个简单的单页网络应用程序。它从两个不同的 API 获取货币数据(以美元为单位),在成功检索后,promise 被解决,一些计算得出 GBP/Bitcoin 汇率。 我正试图找到一种干净的方法,然
我有以下简单的计算,它将两个值加在一起。这些值与使用“R”作为前缀标识的兰特(南非货币)有关。 function calculate() { var A = parseFloat(docume
使用 JavaScript,什么是将点替换为逗号的正确方法(对于欧盟货币),例如: 2000.65 将是 2000,65 而不是 2,000.65 39.20 将是 39,20 我不确定 cost.r
我在文本框中显示带有 NumberFormat 的货币符号 NumberFormat numberFormat = NumberFormat.getSimpleCurrencyFo
我已经设法从非接触式阅读器读取了一个交易事件,使用 现在我的 Activity 打开了,我被困在那个点上,因为我认为我的 Intent 中会有一些数据,比如 amou
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
这个问题在这里已经有了答案: Why not use Double or Float to represent currency? (16 个答案) 关闭 3 年前。 我的应用程序中的一些计算有问题
我使用 Jruby(反正就是 ruby,在 jvm 下运行 :D )和马拉松测试(一个 java swing 应用程序),我在处理货币数字时遇到了一些麻烦。 我不使用 Rails(不知道我是否可以
我正在尝试删除 、 或 之后的尾随零。 以一种货币表示,仍然保留货币符号。例如,€90.00 到 €90、90.00€ 到 90€ 和 €90.33 到 €90.33。 示例如下: $('.produ
我想将带小数点的数字(以货币计)转换成单词 例如:12345.60--> 一万二千三百四十五美元六十美分 我从 http://www.csharp-tutorials.info/2016/04/con
我是一名优秀的程序员,十分优秀!