gpt4 book ai didi

jquery - 使用 Jquery 根据其内容隐藏

转载 作者:行者123 更新时间:2023-11-30 23:51:00 25 4
gpt4 key购买 nike

我正在努力实现以下目标:

某个页面会有一系列字符串,如果数据库内容存在,则将其替换。
例如:

<h2 class="label">Title:</h2>
<p class="value">{{Title}}</p>

会变成:

<h2 class="label">Title:</h2>
<p class="value">This is the title</p>

问题是,如果从未输入过 {{Title}} 的数据库行,它会显示 {{Title}} 而不是用空格替换它。所以 id 喜欢做的是,使用 jquery,如果 .value 包含 {{,则隐藏整个元素,就像 display:none 一样。

这可能吗?

提前致谢。
罗布

最佳答案

$(function () // when DOM is ready for manipulation, do:
{
// for each of the p-elements in the DOM (add your own context or class-scope
// or whatever you can do to narrow down the list of elements here):
$("p").each(function ()
{
// cache the element (always a good idea when doing multiple operations
// on the same entity):
var that = $(this);

// if the text of the element is "{{Title}}" then hide the element:
if (that.text() == "{{Title}}") that.hide();

// alternatively you can do:

// if the the characters "{{" exists at any position in the text of the
// element, hide it:
if (that.text().indexOf("{{") > -1) that.hide();
});
});

关于jquery - 使用 Jquery 根据其内容隐藏 <p>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1519023/

25 4 0
文章推荐: javascript - JS : Entering a TRUE value into a prompt box and having it alert its variable
文章推荐: jquery - 从 jQuery-UI 选项卡获取目标 URL
文章推荐: jquery - 使用 JQuery 将值添加到下拉