我试图找出这是否完全可能,我有一个类似下面的标记的设置:

<div class="price-wrap">£12.95</div>
<div class="price-wrap">from £9.95</div>
<div class="price-wrap">£6.95</div>
<div class="price-wrap">£16.95</div>
<div class="price-wrap">£11.95</div>
<div class="price-wrap">from £1.95</div>


但是如果可能的话,我理想的情况是这样的:

<div class="price-wrap">£<span class="price">12.95</span></div>
<div class="price-wrap">from £<span class="price">9.95</span></div>
<div class="price-wrap">£<span class="price">6.95</span></div>
<div class="price-wrap">£<span class="price">16.95</span></div>
<div class="price-wrap">£<span class="price">11.95</span></div>
<div class="price-wrap">from £<span class="price">1.95</span></div>


因此,只需将数字包装在带有span类的price标记中,排除任何£from等,等等。
任何建议将不胜感激!

最佳答案

应该这样做:

$('.price-wrap').each(function() {
    var $this = $(this);
    $this.html($this.html().replace(/([0-9.]+)/g, '<span>$1</span>'));
});

07-24 18:05