2014-04-28 70 views
0

我有这个jquery检查h2是否包含Simple这个词,但我不知道为什么它不适合我? 这是我的脚本,这里是我试图检查。jquery检查h2是否包含特定文本

<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

回答

0

可以使用indexOf()方法,看是否有字符串包含在JS。我在演示中忽略了data-bind的部分。

DEMO

<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> 
+0

所以如何将添加数据绑定?我试过你的,它仍然没有隐藏,我非常感谢你的帮助 – user3546263

+0

@ user3546263你使用基诺(JavaScript)? –

+0

是的......我只是想要它隐藏它,如果h2说简单...... lol – user3546263

相关问题