gpt4 book ai didi

javascript - 替换键盘上的符号

转载 作者:行者123 更新时间:2023-12-01 04:08:31 24 4
gpt4 key购买 nike

我偶然发现了一个问题,我不明白为什么会发生(不起作用)。

我要做的只是替换 1 的 amount 值,由于某种原因我不能哈哈。

当用户输入金额时,如果他输入“,”,我必须将其更改为“。”立即 - 直播。

这是示例..

$(document).ready(function() {
// Uberfix Amount
$(".form-amount").keyup(function() {
var amount = $(".form-amount").val();
$(".form-amount").val().replace(",", ".");
alert('passed');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<input type="text" class="form-amount" id="textare" value="" placeholder="0.1 BTC - 10 BTC" />

最佳答案

这是因为你改变文本框的值后没有设置它的值。请参阅下面的工作代码:

$(document).ready(function() {
// Uberfix Amount
$(".form-amount").keyup(function() {
var $this = $(this), amount = $this.val();
$this.val(amount.replace(",", "."));
console.log('passed');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<input type="text" class="form-amount" id="textare" value="" placeholder="0.1 BTC - 10 BTC" />

关于javascript - 替换键盘上的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41647166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com