jQuery表格排序

时间:2012-07-19 14:08:38

标签: php jquery tablesorter

我正在使用位于here的jQuery表格排序器,而不是对我的表进行排序。我在一个简单的测试页面上使用了完全相同的代码,它没有问题。如果有人能指出可能导致我的问题在我的代码中出现的问题那将是非常好的。

以下是调用JS文件的代码,路径是正确的。

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<script type="text/javascript" src="../js/jquery-latest.js"></script> 
<script type="text/javascript" src="../js/jquery.tablesorter.js"></script>
</head>

以下是我的代码片段,其中包含需要排序的表格。

<div id="roster">
<?php
$guildRealm = "taken out";
$guildName = "taken out";

$json = file_get_contents("http://us.battle.net/api/wow/guild/".$guildRealm."/".$guildName."?fields=members");
$json= json_decode($json);
$name = $json->name;
$level = $json->level;
$achievementPoints = $json->achievementPoints;

?>

<span class="h2"><?php echo $name; ?></span><br />
<span class="h4">Level: <?php echo $level; ?></span><br />
<span class="h5"><img src="images/guild_achievement_icon.png" width="38" height="32">    </span><span class="AP"><?php echo $achievementPoints; ?></span><br />
<table id="gRoster" class="tablesorter" width="100%" cellspacing="0">
<thead>
<tr class="roster-header">
    <th width="5%"></th>
    <th align="left">Name</th>
    <th align="center">Rank</th>
    <th align="center">Level</th>
    <th align="center">Class</th>
    <th align="center">Race</th>
    <th align="center">Achievement Points</th>
</tr>
</thead>

<?php
$count = 0;

foreach($json->members as $p) {
    $mrank = $p->rank;
    $mname = $p->character->name;
    $mclass = $p->character->class;
    $mrace = $p->character->race;
    $mgender = $p->character->gender;
    $mlevel = $p->character->level;
    $mthumb = $p->character->thumbnail;
    $machievement = $p->character->achievementPoints;
    $colour = "default";
    $mraceImage = "images/inv_misc_questionmark.jpg";
    $mclassImage = "images/inv_misc_questionmark.jpg";
    $mgrank = "";

    // Alot of if statements go here that just display how some of the content is display, already tested and they do not cause the problem.

    if ($count%2==0) {
        echo "<tbody>";
        echo "<tr class=\"even\">";
        echo "<td class=\"roster-avatar\"><img src=\"http://us.battle.net/static-render/us/".$mthumb."?alt=/wow/static/images/2d/avatar/".$mrace."-".$mgender.".jpg\" width=\"40\" height=\"40\" class=\"".$colour."\"></td>";
        echo "<td class=\"roster-name\"><span class=\"".$colour."\">".$mname."</span></td>";
        echo "<td align=\"center\">".$mgrank."</td>";
        echo "<td align=\"center\">".$mlevel."</td>";
        echo "<td align=\"center\"><img src=\"".$mclassImage."\" /></td>";
        echo "<td align=\"center\"><img src=\"".$mraceImage."\" /></td>";
        echo "<td align=\"center\">".$machievement."</td>";
        echo "</tr>";
        echo "</tbody>";
    } else {
        echo "<tbody>";
        echo "<tr class=\"odd\">";
        echo "<td class=\"roster-avatar\"><img src=\"http://us.battle.net/static-render/us/".$mthumb."?alt=/wow/static/images/2d/avatar/".$mrace."-".$mgender.".jpg\" width=\"40\" height=\"40\" class=\"".$colour."\"></td>";
        echo "<td class=\"roster-name\"><span class=\"".$colour."\">".$mname."</span></td>";
        echo "<td align=\"center\">".$mgrank."</td>";
        echo "<td align=\"center\">".$mlevel."</td>";
        echo "<td align=\"center\"><img src=\"".$mclassImage."\" /></td>";
        echo "<td align=\"center\"><img src=\"".$mraceImage."\" /></td>";
        echo "<td align=\"center\">".$machievement."</td>";
        echo "</tr>";
        echo "</tbody>";
    }
    $count++;
}
?>
</table>

<script type="text/javascript">
$(document).ready(function() 
    { 
        $("#gRoster").tablesorter();
    } 
); 
</script>
</div><!--- roster --->

1 个答案:

答案 0 :(得分:1)

我看到两种可能性:

  1. 你创建了多个 - 块
  2. 你的变量不是HTML安全的(比如$ machievement可能包含与HTML相关的字符) - 你至少应该使用htmlspecialchars()