0
4

2 回答 2

4

How about this:-

Demo

$('body:contains("•")').contents().each(function () {
    if (this.nodeType == 3) {
        $(this).parent().html(function (_, oldValue) {
            return oldValue.replace(/•/g, "<span class='bullets'>$&</span>")
        })
    }
});

Try avoid using *. probably even body. Try using the outermost container as possible.

This should also work

Demo

$('body:contains("•&quot;)').contents().each(function () {
    if (this.nodeType == 1) { //Look for only element Nodes
        $(this).html(function (_, oldValue) {
            return oldValue.replace(/•/g, "<span class='bullets'>$&</span>")
        })
    }

Node Types

于 2013-05-29T00:55:07.587 回答
0
$("*").each(function() { 
    if($(this).children().length==0) { 
        $(this).html($(this).html().replace(/•/g, '<span class="bullets">•&lt;/span>')); 
    } 
});

This answer is based of this question

Js Fiddle Example

于 2013-05-29T00:55:20.883 回答