我正在使用表格和一些CSS来实现用户的外观。
这些表是由其他jquery插件制成的,例如dataTable
http://www.datatables.net/
而我的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
,下面是您可以清楚理解的图像。
和下面的CSS代码
.tr_class {
background-color: #CCB;
}
.tr_class_head {
background-color: #CCE;
}
参考方案
基本上,您是在使用类来应用样式,而数据表使用它们的类对行进行排序,这可能导致3个奇数行彼此相邻。我最近使用了数据表,并做了一些样式更改,但我的样式不需要奇数和偶数行样式。您可以尝试这样做,但我不能保证它会成功:
tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}
希望能帮助到你。
PHP-复选框组 - php我有一个需要发布的表单复选框组。<input type="checkbox" value="true" checked name="chk0[]"> <input type="checkbox" value="false" name=…
php Singleton类实例将在多个会话中保留吗? - php举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…
Div单击与单选按钮相同吗? - php有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date…
使用Ajax呈现html表 - php我想知道如何实现以下项目其实我有一个php代码,可以渲染一张桌子<table id = "oldata" class ="table table-bordered"> <thead> <tr class ="success"> <th class="…
提交表单后显示模式对话框 - php提交下载文件后,我有一张表格。我要自动而不是自动下载文件..以显示模态对话框并显示下载链接。<form name="softwareform" id="softwareform" action="../downloadlink.php" method="POST" alig…