【发布时间】:2021-03-26 18:34:23
【问题描述】:
我需要如下图所示的输出。 我创建了三个输入,并将它们放在下面的框中。我怎么能有这样的输出? 请帮忙举个例子
注意:假设我们有 50 个输入并且类相同 获取ID后无法使用
我的 HTML 代码
<span class="pricing-heading">Your sale price:</span><div class="pricing-field"><input class="pricing-set-price" type="number" value="24.00"></div>
</div>
<div class="prt-pricing-detial">
<span class="pricing-heading">Product base Cost:</span><div class="pricing-field"><input class="pricing-base-price" type="number" value="10.00" disabled></div>
</div>
<div class="prt-pricing-detial">
<span class="pricing-heading">Your profit:</span><div class="pricing-field"><input class="pricing-profit" type="number" value="14.00" disabled></div>
</div>
JS 代码:
$(".pricing-set-price").change(function(){
var item_rrp = $(this).val();
var item_base = $(this).parent().parent().parent().find('.pricing-base-price').val();
var profit = item_rrp - item_base;
var profit_format = profit.toFixed(2);
$(this).parent().parent().parent().find('.pricing-profit').val(profit_format);
});
【问题讨论】:
-
do not be bored???代码尝试(来自您)意味着您尽可能地关心我们可能会尝试关心。这是诚意的体现。 -
@Swati 它在 Chrome 浏览器上对我有效,但在 Safari 上无效
-
@sonali 不能在 chrome 上工作:D
-
请解释[lain your note
-
我用了你说的方法,但问题是我们有几十个输入。见以下链接:alomykar.ir/qw当我们在第二个和第三个输入以及其他想法是SalePrice的输入中更改SalePrice的值时,第一个输入的利润发生了变化,这是不正确的。@sonali
标签: javascript html node.js ajax