我正在努力实现以下目标:
某个页面会有一系列字符串,如果数据库内容存在,则将其替换为数据库内容。
例如:
<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 一样。
这可能吗?
提前致谢。
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();
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)