2

我之前发布了一个类似的问题,但这有点不同。我希望使用 jQuery 从下面的价格代码中删除冒号。

 <font class="pricecolor colors_productprice">
       <div class="dealtext"></div>
       :  $58.05
 </font>

到目前为止,我相信它可以像这样完成,我只需要另一双眼睛来纠正它:

$('.pricecolor:contains(" : ")').remove(colon??);

它似乎仍然不正确,也许我需要一个带有get()?的 var 集

4

7 回答 7

4
$('*').each(function() {
  $(this).html($(this).html().replace(":", ""));
});
于 2011-09-02T16:43:32.357 回答
1

我发现了这个问题,因为我需要它,我最终使用这个函数来做类似的事情......

$('.pricecolor:contains(" : ")').html(function(index,oldhtml) {
    return oldhtml.replace(' : ','');
});
于 2012-06-22T19:16:07.197 回答
0

Give this a shot:

$('.pricecolor:contains(" : ")').text(function(index, text) {
    return text.replace(/:/g, "");
});

I think you need to pass a function instead of a string to $.text() like this to avoid mangling other content that was found using the '.pricecolor:contains(" : ")' selector.

于 2011-09-02T16:52:41.830 回答
0
function findAndReplace(elements, textToFind, textToPlace) {
            $.each(elements.contents(), function () {
                // This is added to make sure the nodes you request are text nodes
                if (this.nodeType == 3)
                    this.nodeValue = this.nodeValue.replace(textToFind, textToPlace);
            });

        }

        findAndReplace($('div.dealtext'), ':');
于 2011-09-02T16:40:39.473 回答
0

我认为您可以执行以下操作。

  $(".pricecolor colors_productprice").html($(".pricecolor colors_productprice").html()replace(/:/g, ""))

希望这可以帮助!!

于 2011-09-02T16:43:57.337 回答
0
var e = $(".pricecolor:contains(':')");
e.text(e.text().replace(/\s*:\s*/, ''));
于 2011-09-02T16:47:17.540 回答
0

这将起作用:

$(".pricecolor:contains(' : ')").each(function(){
    $(this).html($(this).html().replace(" : ", ""));
});
于 2011-09-02T16:47:58.580 回答