gpt4 book ai didi

javascript - 从变量 jQuery 中减去 1

转载 作者:行者123 更新时间:2023-11-30 20:20:25 24 4
gpt4 key购买 nike

在正确执行此操作时遇到了一些麻烦。我是 jQuery 的新手,所以想变得更好并学习。

目前我使用以下代码从 html 表中获取 2 个不同的值

var sellPrice = $('.qt').find("tr:eq(2)").find("td:eq(4)").html();
var buyPrice = $('.break .main-col .qt').find("tr:eq(2)").find("td:eq(4)").html();

这些都输出了一个值,例如 $13,000,000
然后我想从这些值中减去 1(使其为 12,999,999 美元),然后再将它们粘贴到这样的输入中

$('input[name="sell"]').val(sellPrice);
$('input[name="buy"]').val(buyPrice);

但是,我在如何从中减去 $1 时遇到了一些麻烦。我尝试使用 sellPrice--; 但没有成功。我也试过在每个变量的末尾添加 - 1;,但也没有成功。

我试图测试类似的东西,但也没有用。

var minusOne = -1;
var getCurrentSellPrice = $('.qt').find("tr:eq(2)").find("td:eq(4)").html();
var getCurrentBuyPrice = $('.break .main-col .qt').find("tr:eq(2)").find("td:eq(4)").html();

var sellPrice = (getCurrentSellPrice - minusOne);
var buyPrice = (getCurrentBuyPrice - minusOne);

$('input[name="sell"]').val(sellPrice);
$('input[name="buy"]').val(buyPrice);`

尽我所能熟悉 jQuery :)
任何帮助深表感谢!

最佳答案

用这个解决了

var getCurrentSellPrice = $('.qt').find("tr:eq(2)").find("td:eq(4)").html();
var getCurrentBuyPrice = $('.break .main-col .qt').find("tr:eq(2)").find("td:eq(4)").html();

var sellPrice = Number(getCurrentSellPrice.replace(/[^0-9\.]+/g,"")) - 1;
var buyPrice = Number(getCurrentBuyPrice.replace(/[^0-9\.]+/g,"")) + 1;

$('input[name="sell"]').val(sellPrice);
$('input[name="buy"]').val(buyPrice);

关于javascript - 从变量 jQuery 中减去 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51509622/

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