0

我想在加载页面后使用这个指令(使用 .load 方法)

this.innerHTML = this.innerHTML.replace(/\bok\b/g, '<img src="ok.png" alt="good word"/>')

我想在页面加载后为所有<p>拥有的人使用它。class="special"

这个怎么做 ?

谢谢

4

2 回答 2

0

如果它在页面加载中,那么

jQuery(function(){
    $('p.special').html(function(idx, html){
        return html.replace(/\bok\b/g, '<img src="ok.png" alt="good word"/>')
    })
})

如果它使用动态元素加载 using .load(),那么在加载回调中您可以添加$('p.special').html(...)

于 2013-09-22T16:46:59.977 回答
0

StackOverflow 不是一种代码编写服务,但无论如何,这是一个快速的服务。

$(function() {
    $('p.special').each(function() {
        $(this).html(function(i,html) {
            return html.replace(/\bok\b/g, '<img src="ok.png" alt="good word"/>');
        });
    });
});
于 2013-09-22T16:43:24.837 回答