是否可以使用css

时间:2016-10-17 14:43:57

标签: html css

我有一个span列表,每个范围有两个数据属性data-searchdata-get-search,所以我想要做的只是显示只有{{{}的跨度1}}等于data-search,类似这样:

查看代码段



data-get-search

   .child:not([data-search *=data-get-search]) {
        display: none;
      
            }




1 个答案:

答案 0 :(得分:0)

与评论中建议的@Pete一样,你应该使用javascript。

类似的东西:

代码段:

(function() {

  var child = document.querySelectorAll(".child");

  for (var i = 0; i < child.length; i++) {
    var dataSearch = child[i].getAttribute("data-search"),
      dataGetSearch = child[i].getAttribute("data-get-search");

    if (dataSearch === dataGetSearch) {
      child[i].style.display = "none";
    }
  }
})();
<div id="main" class="container">
  <div class="child" data-search="first" data-get-search="first"><span>first</span>
  </div>
  <div class="child" data-search="second" data-get-search="first"><span>second</span>
  </div>
  <div class="child" data-search="third" data-get-search="first"><span>third</span>
  </div>
  <div class="child" data-search="fourth" data-get-search="first"><span>fourth</span>
  </div>
  <div class="child" data-search="fifth" data-get-search="first"><span data-search="fifth">fifth</span>
  </div>
</div>