Php jquery检查h2是否包含特定文本
我用jquery检查h2是否包含单词Simple,但我不确定为什么它对我不起作用? 这是我的脚本,这是我要检查的内容Php jquery检查h2是否包含特定文本,php,jquery,data-binding,Php,Jquery,Data Binding,我用jquery检查h2是否包含单词Simple,但我不确定为什么它对我不起作用? 这是我的脚本,这是我要检查的内容 <section class="main"> <nav> <a class="show-menu"><i class="fa fa-bars fa-lg"></i></a> <ul> <li class="static ac
<section class="main">
<nav>
<a class="show-menu"><i class="fa fa-bars fa-lg"></i></a>
<ul>
<li class="static active"><a href="theme"><?php print _("Themes"); ?></a></li>
</ul>
</nav>
<div id="themesList" class="image-list" data-bind="foreach: themes">
<div class="image-item" data-bind="css:{active: ($parent.theme()==id())}">
<h2 data-bind="text: name"></h2>
<img data-bind="attr:{'src': 'themes/'+id()+'/logo.png'}">
<div class="preview-button">
<a data-bind="attr: { href: 'themes/'+id()+'/logo.png'}" data-lightbox="+id()+" data-title=data-bind="attr: { text: 'name'}">Preview</a>
</div>
<div class="secondary inactive-button" data-bind="click: $parent.showApplyDialog"><?php print _("Apply Theme"); ?></div>
<div class="active-button" data-bind="click: $parent.showResetDialog"><?php print _("Reset Theme"); ?></div>
</div>
<script type="text/javascript">
var $h2 = $('.image-item h2');
if ($h2.text().indexOf('simple') > -1) {
$h2.hide();
}
</script>
</div>
<!-- /.list -->
</section>
<!-- /.main -->
数据绑定是填充h2的内容。您可以使用indexOf方法查看字符串是否包含在js中。我在演示中遗漏了带有数据绑定的部分
那么如何添加数据绑定呢?我试过你的,但它仍然没有隐藏,我非常感谢你的帮助much@user3546263你在使用击倒javascript吗?是的。。。我只是想把它藏起来如果h2说的很简单。。。lol@user3546263它是区分大小写的,所以请确保您检查的Simple与h2中的相同。我检查了,但它仍然不是。。。我应该把脚本放在上面还是下面?
<script type="text/javascript">
$(document).ready(function () {
var $h2 = $('.image-item h2');
//add this
console.log($h2);
console.log('text: ' + $h2.text());
if ($h2.text().indexOf('Simple') > -1) {
$h2.hide();
}
});
</script>