gpt4 book ai didi

javascript - 如何查找方括号之间的字符串并将其包装在 CSS 类中

转载 作者:行者123 更新时间:2023-12-03 01:23:13 25 4
gpt4 key购买 nike

我有以下段落:

deemed to be safe and effective for fat reduction by about 20% atcertain body sites. As a medical procedure, cryolipolysis is anonsurgical alternative to liposuction. [gallery ids="16,15,14"]

如何找到 [ ] 中的所有字符串并将它们包装在 首选类 中?

.hidden{
display:none !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="post-paragraph">The degree of exposure to cooling causes cell death of subcutaneous fat tissue, without apparent damage to the overlying skin.The method has a low rate of complications, and is deemed to be safe and effective for fat reduction by about 20% at certain body sites. As a medical procedure, cryolipolysis is a nonsurgical alternative to liposuction. [gallery ids="16,15,14"]</p>

<p class="post-paragraph">The degree of exposure to cooling causes cell death of subcutaneous fat tissue, without apparent damage to the overlying skin.The method has a low rate of complications, and is deemed to be safe and effective for fat reduction by about 20% at certain body sites. As a medical procedure, cryolipolysis is a nonsurgical alternative to liposuction. [gallery ids="23,22,21,20"]</p>

最佳答案

您可以找到包含 div class hide 的文本和换行,如下所示。

$('p').each(function(index, element) {
var str = $('.post-paragraph').text();
var start = str.indexOf('[');
var end = str.indexOf(']', start) + 1;
var text = str.substring(start, end)
$("p:contains(" + text + ")").html(function(_, html) {
return html.split(text).join("<div class='hidden'></div>");
});
});
.hidden {
display: none !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="post-paragraph">The degree of exposure to cooling causes cell death of subcutaneous fat tissue, without apparent damage to the overlying skin.The method has a low rate of complications, and is deemed to be safe and effective for fat reduction by about 20% at certain
body sites. As a medical procedure, cryolipolysis is a nonsurgical alternative to liposuction. [gallery ids="16,15,14"]</p>

<p class="post-paragraph">The degree of exposure to cooling causes cell death of subcutaneous fat tissue, without apparent damage to the overlying skin.The method has a low rate of complications, and is deemed to be safe and effective for fat reduction by about 20% at certain
body sites. As a medical procedure, cryolipolysis is a nonsurgical alternative to liposuction. [gallery ids="23,22,21,20"]</p>

关于javascript - 如何查找方括号之间的字符串并将其包装在 CSS 类中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51665304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com