2013-12-23 26 views
1

我有奇怪的錯誤,並且不明白爲什麼! 可能有人可以幫助我,告訴,這裏有什麼問題。無法使用'in'運算符在.top10_month .periods中搜索'20'

Page.contentSort = function() { 
    var $eachblocks = (".top10_month .periods"); 
    var $blockhead = $(".block-head__link"); 
    $blockhead.on("click", function (e) { 
     var $this = $(this); 
     var sortvalue = $this.attr("data-date"); 
     e.preventDefault(); 
     $this.parents("ul").find("a").removeClass("active"); 
     this.className += " active"; 
     $.each($eachblocks, function() { 
      if ($eachblocks.attr("data-period") === $(".block-head__link.active").attr("data-date")) { 
       $(this).addclass("active"); 
      } else { 
       $eachblocks.removeClass('active'); 
      } 
     }); 
    }); 
}; 

回答

0

你已經錯過了$,所以不是

var $eachblocks = (".top10_month .periods"); 

使用

var $eachblocks = $(".top10_month .periods"); 

此外,您應該使用.data()代替.attr()

所以不是

var sortvalue = $this.attr("data-date"); 

使用

var sortvalue = $this.data("date"); 

你應該去深入jQuery Data vs Attr?

+0

謝謝,這是有益的 –

0

試圖讓數據屬性像以下,而不是使用.attr();

$this.data("date"); 
$this.data("period"); 
相關問題