我目前正在努力的脚本,应该取代一些文本,并使其通过css加粗。
但我的问题是,脚本没有循环。它只需要第一个文本。
有人能帮我吗?
这是my fiddle
这是我的密码

$(document).ready(function (i) {
$('.main:contains("*")').each(function () {
    $(this).html($(this).html().replace('*', '<span class="highlight">'));
    $(this).html($(this).html().replace('*', '</span>'));
});

});

最佳答案

这个也有诀窍:

$(document).ready(function (i) {
    function replace(o) {
        $(o).html($(o).html().replace('*', '<span class="highlight">'));
        $(o).html($(o).html().replace('*', '</span>'));
        if ($(o).html().indexOf("*") >= 0) {
            replace(o);
        }
    }
    replace('.main:contains("*")');

});

10-05 20:45
查看更多