我使用表和一些css用户的外观和感觉。 而且这些表都做了一些其他jQuery插件一样的dataTablejquery,css不申请表
而且我的PHP代码如下
<table width="100%" id="top_visit_table">
<thead>
<tr align="left">
<th>Product Id</th><th>Product Name</th><th>Product Price</th><th>Number of Views</th>
</tr>
</thead>
<tbody>
<?php get_views_of_products($user_id);?>
</tbody>
</table>
而且下面是jQuery的CSS代码
<script type="text/javascript">
$(document).ready(function(){
$('#top_visit_table').dataTable();
$("#top_visit_table tbody tr:even").addClass('tr_class'); // this gives color to table
$("#top_visit_table thead tr").addClass('tr_class_head'); // this gives color to table
});
</script>
和功能下面的代码
function get_views_of_products($user_id) {
$fquery12 = mysql_query("select p.products_id, pd.products_name, p.products_price, pd.products_viewed
from products p
INNER JOIN products_description pd ON pd.products_id = p.products_id
ORDER BY pd.products_viewed DESC
");
while($fr12 = mysql_fetch_row($fquery12)) {
$price = substr($fr12[2], 0, -2);
echo "<tr>";
echo "<td>$fr12[0]</td>";
echo "<td>$fr12[1]</td>";
echo "<td>$price</td>";
echo "<td>$fr12[3]</td>";
echo "</tr>";
}
}
当我点击任何th
元素,然后css
排序并不适用于tr
或td
以下是图像,你可以把它理解清楚。
及以下
.tr_class {
background-color: #CCB;
}
.tr_class_head {
background-color: #CCE;
}
我已经测试这个,它的作品完美。 – Nightwolf 2012-03-19 09:16:21
优秀的男人!它的工作。谢谢..你能告诉我,这个代码是如何工作的。 – Rafee 2012-03-19 09:19:55