繁体   English   中英

如何在给定特定条件后隐藏标签?

[英]How to hide a tag after given speciffic condition?

我有这个 Handlebars 模板:

<div class="card-body">          
  <h5 class="card-title"><i class="fa fa-users" aria-hidden="true"></i> {{ this.group }}
    <i class="fa fa-user" aria-hidden="true"> </i> {{ this.name }} {{ this.lastName }}
  </h5>
  <a href="https://wa.me/{{ this.phone }}"><i class="fa fa-whatsapp" aria-hidden="true"></i> {{ this.phone }}</a><br>
  <i class="fa fa-home" aria-hidden="true"></i> {{ this.address }} <br>
  <a href="mailto:{{ this.email }}"><i class="fa fa-envelope" aria-hidden="true"></i> {{ this.email }}</a> 
  <br>          
  <hr>
  <p class="card-text">  
    <a class="facebook" href="https://www.facebook.com/{{ this.facebook }}" > <i class="fa fa-facebook" aria-hidden="true"></i></a>
    <a href="https://www.instagram.com/{{ this.instagram }}" ><i class="fa fa-instagram" aria-hidden="true"></i></a>
    <a href="https://twitter.com/{{ this.twitter }}"><i class="fa fa-twitter" aria-hidden="true"></i></a>
    <a href="https://www.linkedin.com/in/{{ this.linkedIn }}"><i class="fa fa-linkedin" aria-hidden="true"></i></a><br>                
  </p>
</div>

我想隐藏所有不会获得“href”值的“a”标签。

我试过这个,例如-

<script>                           
    if (!document.getElementsByClassName("facebook").value) {      
      $(".facebook").hide();
    }    
</script>

但它隐藏了所有“a”标签,无论是否符合条件。 我猜这一定与迭代每个生成的标签有关,但我不知道如何定位它们。

您可以使用each

$("a").each(function() {
    if($(this).attr("href") == "") {
        $(this).hide();
    }
});

了解更多: https : //api.jquery.com/each/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM