我试图从两个数字中获取百分比。如果你在小提琴上玩耍,它会与第一个数字一起工作。对于第二个数字,我需要多修整一个数字,但不确定如何。修剪除数字以外的所有字符
第一个数字的作品。
第二个数字需要一个正则表达式,用于删除数字后面的空格和字符。
第三个需要一个正则表达式来删除数字和点之后的所有字符之间的逗号。
第四个需要一个正则表达式的数字之前删除字符,后面
数字和点之间的所有字符之间的逗号我怎样写它,所以它适用于所有的情况?无论我尝试什么,只是刹车一个或其他人。
小提琴:
https://jsfiddle.net/28dL2fvp/5/
脚本:
$('.left').each(function() {
var frstCol = parseInt($(this).find('em.price.product-card-price').text().trim().replace(/[€\.]/g, ''), 10);
var seCol = parseInt($(this).find('em.price.product-card-price.before').text().trim(), 10);
var result = (frstCol/seCol) * 100;
$(this).find('a.pricebubble').text(parseInt(result)|| 0);
});
HTML:
<div class="left">
<em class="price product-card-price">
€1.019 // should count as 1019
<span class="vatstatus">Exclusief BTW</span>
</em>
<em class="price product-card-price before">
1519
</em>
<a class="pricebubble"></a>
</div>
<div class="left">
<em class="price product-card-price">
5 995:- // should count as 5995
<span class="vatstatus">Exclusief BTW</span>
</em>
<em class="price product-card-price before">
987
</em>
<a class="pricebubble"></a>
</div>
<div class="left">
<em class="price product-card-price">
11,823.00SEK // should count as 1183
<span class="vatstatus">Exclusief BTW</span>
</em>
<em class="price product-card-price before">
1987
</em>
<a class="pricebubble"></a>
</div>
<div class="left">
<em class="price product-card-price">
SEK11,823.00 // should count as 1183
<span class="vatstatus">Exclusief BTW</span>
</em>
<em class="price product-card-price before">
1987
</em>
<a class="pricebubble"></a>
</div>
你想过滤哪个变量? – Roysh