我有一些代码如下:
<p class="fp-excerpt fp-text-one text-random-override">[image caption]I don't want this text[/image caption]Lorem Ipsum Text</p>
<p class="fp-excerpt fp-text-one text-random-override">[image caption]I don't want the text here too[/image caption]Lorem Ipsum Text number two</p>
如何使用jQuery定位段落类并删除[image caption]和[/ image caption]标签,以及中间的随机文本?
谢谢!
答案 0 :(得分:5)
我就是这样做的:
$(".text-random-override").each(function(){
$(this).html($(this).html().replace(/\[image caption\].+\[\/image caption\]/g,""));
});
答案 1 :(得分:0)
<html>
<head>
<title>sample Page</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<style>
.check-with-label:checked + .label-for-check {
font-weight: bold;
}
</style>
<script>
$(document).ready(function () {
$('p.text-random-override').each(function () {
var szData = $(this).text();
szData = szData.replace(/((.)*)(\[image caption\])((.)*)(\[\/image caption\])((.)*)/g, "$7");
$(this).text(szData)
});
});
</script>
</head>
<body>
<p class="fp-excerpt fp-text-one text-random-override">[image caption]I don't want this text[/image caption]Lorem Ipsum Text</p>
<p class="fp-excerpt fp-text-one text-random-override">[image caption]I don't want the text here too[/image caption]Lorem Ipsum Text number two</p>
</html>