jQuery将类添加到html引号和转义
我想在blockquote中的每个双引号实例中添加一个带有类的span 我可以检查blockquote的内容,并用双引号以外的任何内容进行替换。我假设这是一个逃避双引号的问题,我尝试过使用斜杠,但我似乎无法让这个工作jQuery将类添加到html引号和转义,jquery,css,Jquery,Css,我想在blockquote中的每个双引号实例中添加一个带有类的span 我可以检查blockquote的内容,并用双引号以外的任何内容进行替换。我假设这是一个逃避双引号的问题,我尝试过使用斜杠,但我似乎无法让这个工作 $(document).ready(function(){ $('blockquote:contains(")').each(function(){ $(this).html( $(this).html().replace('"','<span cla
$(document).ready(function(){
$('blockquote:contains(")').each(function(){
$(this).html(
$(this).html().replace('"','<span class=\'green\'>"</span>')
);
});
});
<blockquote>
"Hello World"
</blockquote>
$(文档).ready(函数(){
$('blockquote:contains(“)”)。每个(函数(){
$(this.html)(
$(this.html().replace(“,”))
);
});
});
“你好,世界”
每个引号周围都应该有一个span,并且应该以粗体绿色样式显示。在我的示例中,没有添加span/class/style。您应该使用
“
而不是”
,来搜索和替换,并且使用正则表达式匹配块引号中的所有”
:
$(文档).ready(函数(){
$('blockquote:contains(“)”)。每个(函数(){
$(this.html)(
$(this.html().replace(/“/g,”))
);
});
});
.green{
颜色:绿色;
字体大小:14px;
字体大小:粗体;
}
“你好,世界”