按值排序div

时间:2015-01-24 13:53:56

标签: javascript sorting

我正在尝试使用js在子里面对文章进行排序。

我使用Expression Engine的文章html如下所示:

<article class="panel panel-default leaderBoard races hidden-xs">
<div class="panel-body">
    <div class="col-lg-3 col-md-3 col-sm-3 hidden-xs col-xs-3">
        <div class="stat"><span>{count}</span></div>
    </div>
    <div class="col-lg-3 col-md-3 col-sm-3">
        <h3><a href="{site_url}/drivers/home/{screen_name}">{first_name} {last_name}</a></h3>
    </div>
    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="profilePic"><a href="{site_url}/drivers/home/{screen_name}"><img src="{profile_image:Square}" alt="{title}" class="img-circle driver img-responsive" width="100" height="100" /></a></div>
    </div>

    <div class="col-lg-3 col-md-3 col-sm-3">
        {relationship}
            {if '{relationship:results_grid:total_rows search:session="Race" sort="desc"}' >= 10 && '{relationship:results_grid:total_rows search:session="Race" sort="desc"}' <= 24}
            <div class="badgeHolder img-responsive" style=" background: url('/images/badges/100/bronze.png') no-repeat;" class="badgeSmall img-responsive">
                <div class="totalRows">{relationship:results_grid:total_rows search:session="Race" sort="desc"}</div>
            </div>
            {if:elseif '{relationship:results_grid:total_rows search:session="Race"}' >= 25 && '{relationship:results_grid:total_rows search:session="Race"}' <= 49}
            <div class="badgeHolder img-responsive" style=" background: url('/images/badges/100/silver.png') no-repeat;"  class="badgeSmall img-responsive">
                <div class="totalRows">{relationship:results_grid:total_rows search:session="Race" sort="desc"}</div>
            </div>
            {if:elseif '{relationship:results_grid:total_rows search:session="Race"}' >= 50}
            <div class="badgeHolder img-responsive" style="background: url('/images/badges/100/gold.png') no-repeat;" class="badgeSmall img-responsive">
                <div class="totalRows">{relationship:results_grid:total_rows search:session="Race" sort="desc"}</div>
            </div>
            {if:else}
            <div class="badgeHolder img-responsive" style="background: url('/images/badges/100/locked.png') no-repeat;"  class="badgeSmall img-responsive">
                <div class="totalRows">{relationship:results_grid:total_rows search:session="Race" sort="desc"}</div>
            </div>
            {/if}
        {/relationship}
    </div>
</div>

我基本上想通过div.totalRows降序对文章进行排序。到目前为止,我只能设法返回值,但我不确定下一步该做什么。

到目前为止我所拥有的:

var badgeRaces = document.getElementById('races').getElementsByClassName("totalRows");

function badgeRacesCount(i){
   for(var i = 0; i < badgeRaces.length; i++){
     return badgeRaces[i].innerHTML;
  }
}

任何帮助都将不胜感激。

0 个答案:

没有答案