使用Jquery隐藏< p>根据其内容 [英] Using Jquery to hide <p> based on its contents
本文介绍了使用Jquery隐藏< p>根据其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现以下目标:
Im trying to achieve the following:
某个页面将具有一系列字符串,如果存在,则将其替换为数据库内容.
例如:
A certain page will have a series of strings, which are replaced with database content if it exists.
For example:
<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相同的方式隐藏整个元素.
The problem is, if the database row for {{Title}} has never been entered, it displays the {{Title}} instead of replacing it with whitespace. So what id like to do is, with jquery, if .value contains {{, hide the whole element, in the same way display:none would.
这可能吗?
预先感谢.
罗布
Thanks in advance.
Rob
推荐答案
$(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隐藏< p>根据其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文