Jquery 查找单词并换行div
我没有访问HTML的权限,只有原始文本。是否可以在原始文本中找到像INFO和ENDINFO这样的单词,并使用它们在内容周围环绕一个divJquery 查找单词并换行div,jquery,text,Jquery,Text,我没有访问HTML的权限,只有原始文本。是否可以在原始文本中找到像INFO和ENDINFO这样的单词,并使用它们在内容周围环绕一个div <div> content content content content content INFO Information content information content ENDINFO </div> <div> content content content content content <
<div>
content content content content content
INFO
Information content information content
ENDINFO
</div>
<div>
content content content content content
<div class="INFO">
Information content information content
</div>
</div>
内容内容
信息
信息内容信息内容
ENDINFO
内容内容
信息内容信息内容
这个怎么样
<div id="content">
content content content content content
INFO
Information content information content
ENDINFO
</div>
<div>
content content content content content
<div class="INFO">
Information content information content
</div>
</div>
<script>
$(document)ready(function(){
var content = $('#content').html();
var regex = /INFO.*ENDINFO/gi;
var info = content.match(regex);
$('.INFO').html(info);
});
</script>
内容内容
信息
信息内容信息内容
ENDINFO
内容内容
信息内容信息内容
$(文档)就绪(函数(){
var content=$('#content').html();
var regex=/INFO.*ENDINFO/gi;
var info=content.match(regex);
$('.INFO').html(INFO);
});
问题已经得到了回答,但我在过去创建了一个“搜索荧光灯”。它可能会派上用场:Hiya yep使用。find
查找单词并使用。当您找到该单词时,请使用prepend
。希望这有帮助,干杯!真奇怪。这看起来像是一个实例,在这个实例中,您应该真正了解生成这个字符串的预处理过程。我从来没有用过正则表达式。谢谢效果很好。