該表被diplayed正常,但無法排序。 這兩個.js文件都與.php文件本身位於同一個目錄中。jQuery tablesorter不工作
<html>
<head>
<script src="jquery-1.6.2.js" type="text/javascript"></script>
<script src="jquery.tablesorter.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#tabel").tablesorter();
});
</script>
</head>
<body>
<?php
$con = pg_connect("user=bct password=bct host=localhost port=5432 dbname=users ") or die (pg_last_error());
$query = "SELECT * from users";
$result = pg_query($con, $query);
$t = '<table id="tabel" class="tablesorter">';
$t .= '<thead>';
//next code get column names
for($i=0; $i < pg_num_fields($result); $i++){
$field_info = pg_field_name($result, $i);
$t .= '<th>' . $field_info . '</th>';
}
$t .= '</thead>';
//next code fetch cell content
$t .= '<tbody>';
while ($row=pg_fetch_row($result)){
$t .= '<tr>';
foreach($row as $_column){
$t .= '<td>' .$_column. '</td>';
$temp=$row;
}
$t .= '</tr>';
}
$t .= '</tbody></table>';
echo $t;
pg_close($con);
?>
</body>
</html>
' 「#tabel」'應該是拼寫表 –
$(「#tabel」)< - 錯字! – Paddyd
錯別字,它*確實*匹配表本身的id。不是問題。 –