我有这样的回复数据:
<div class="blog-post">Lorem ipsum dolor sit amet.</div>
<div class="blog-post">Eum perferendis nisi vitae et.</div>
<div class="blog-post">Accusantium odit molestias, excepturi iusto.</div>
<div class="blog-post">Maxime assumenda eaque cum, mollitia.</div>
我尝试使用div.blog-post
在data.replace
中添加新课程,但只更改了一次:
$.ajax({
success:function(data){
data = data.replace('blog-post', 'blog-post is-ready');
}
}
这是输出:
<div class="blog-post is-ready">Lorem ipsum dolor sit amet.</div>
<div class="blog-post">Eum perferendis nisi vitae et.</div>
<div class="blog-post">Accusantium odit molestias, excepturi iusto.</div>
<div class="blog-post">Maxime assumenda eaque cum, mollitia.</div>
如何将整个班级名称blog-post
替换为blog-post is-ready
?
答案 0 :(得分:1)
data.split('blog-post').join('blog-post is-ready'))