您好我正在尝试在从CSV文件生成的HTML表格中创建排序功能。我添加了一些据说可以做到的javascript,但我不是最好的。请指教。
继承我正在使用的代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HKJC Football</title>
<script type="text/javascript" src="http://cscasiapacific.com/tablesort/jquery-latest.js"> </script>
<script type="text/javascript" src="http://cscasiapacific.com/tablesort/jquery.tablesorter.js"></script>
<style type="text/css">
<!--
body {
font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
background-image: url('http://1080phdwallpapers.com/wp-content/uploads/2012/10/kick-the-ball-1080p-hd-wallpaper.jpg');
background-color: #FFFFFF;
margin: 0;
padding: 0;
color: #000;
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border- width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border- style:solid;border-width:1px;overflow:hidden;word-break:normal;}
}
table, th, td {
border: 1px solid black;
}
table, th, td {
background-color: green;
color: white;
}
</style><!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--></head>
</head>
<?php
echo "<html><center><body><table>
<thead>
<tr>
</thead></tr><tbody> \n\n";
$f = fopen("http://www.rittmayer.info/sports/home4/rittmaye/public_html/cscasiapacific/football.CSV", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
}
fclose($f);
echo "\n
</tbody></table>
</body></center></html>";
谢谢!
答案 0 :(得分:0)
您已包含javascript文件但未以任何方式使用它们。在HTML中添加此项。查看关于如何对插件主页上的表进行排序的示例javascript。
Tablesorter要求您的表具有ID。 <table id="myTable">
然后让tableSorter执行tablesorter插件代码所需的代码:
<script type="text/javascript">
$( document ).ready(function() {
$("#myTable").tablesorter();
});
</script>
将它包装在jQuery的.ready()
方法中是必要的,因为你需要等到PHP完成并且页面完全加载,否则javascript可能会过早发生。