请访问:Plnkr.co
<table id="customers">
<tbody>
<tr>
<th>Sales</th>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>12%</td>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
.... ....
</tbody>
</table>我需要部分填充颜色的“销售”颜色,根据百分比,与IE-8兼容性。
请帮帮忙。提前谢谢。
发布于 2014-08-05 10:56:31
您需要使用jquery来实现这一点。查看下面的jquery。我是拿td值,并分配它的div与背景颜色。
$(document).ready(function(){
$("#customers tr td:first-child").each(function(){
var textval = "<div class='bg' style='width:"+$(this).html()+"'> </div>";
$(this).html(textval);
});
});演示
发布于 2014-08-06 06:54:46
你可以试试这样的东西
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#customers').each(function(){
if ($(this) >= 0% && $(this) <= 25%) {
$(this).css('background-color','gray');
}else if ($(this) >= 25% && $(this) <= 50%) {
$(this).css('background-color','red');
}else if ($(this) >= 50% && $(this) <= 75%) {
$(this).css('background-color','red');
}else if ($(this) >= 75% && $(this) <= 100%) {
$(this).css('background-color','green');
}
});
});
</script>
</head>
<body>
<table id="customers">
<tbody>
<tr>
<th>Sales</th>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>12%</td>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
.... ....
</tbody>
</table>
</body>
</html> 发布于 2014-08-05 10:42:13
你可以用jQuery来做这个。条件格式(如Excel),请参见StackOverflow。
https://stackoverflow.com/questions/25136238
复制相似问题