javascript - 如何使用 jQuery 删除跨度数值的 25%?

标签 javascript jquery html string

我想从价格中删除 25%,然后在新范围中显示总和。像这样的事情:

price * 0.8 = newPrice //edited

这是我的跨度:

<span id="ctl00_main_ctl00_ctl00_labPrice" class="price" itemprop="price">21.188</span>

这是我到目前为止所想到的......

$(".purchase-block-price" ).each(function() {

    // Show price ex vat
    var price = parseInt($(".price").text().trim().replace(".",""));
    var newprice = price * 0.8;

    $(newprice).appendTo(".purchase-block-price");
});

这可能吗?

最佳答案

当然,获取该值(在本例中使用 text())并乘以 0.75。

var value = parseFloat( $("#ctl00_main_ctl00_ctl00_labPrice").text() );
var newValue = value * 0.75;
console.log( newValue );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="ctl00_main_ctl00_ctl00_labPrice" class="price" itemprop="price">21.188</span>

关于javascript - 如何使用 jQuery 删除跨度数值的 25%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42694539/

相关文章:

javascript - React 30 天(第 4 天)pdf

javascript - 操作多个子组件的状态

javascript - 在javascript中查找耗时

javascript - 如何使用 ArcGIS Javascript API 旋转 map 图像

javascript - 如何将 3 个不同 div 的可见性切换为三个相应的 div

jquery - 如何将下拉子菜单移动到顶部

javascript - Jquery Header 在悬停时添加类

javascript - jQuery - HTML 中的脚本标记由 jQuery 解析出来并且不执行

php - 确认密码字段

jquery - 滑动效果在 jQuery 中不起作用