首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >部分彩色表格单元可与IE-8兼容

部分彩色表格单元可与IE-8兼容
EN

Stack Overflow用户
提问于 2014-08-05 10:11:12
回答 3查看 310关注 0票数 1

请访问:Plnkr.co

代码语言:javascript
复制
<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兼容性。

请帮帮忙。提前谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-08-05 10:56:31

您需要使用jquery来实现这一点。查看下面的jquery。我是拿td值,并分配它的div与背景颜色。

代码语言:javascript
复制
 $(document).ready(function(){    
   $("#customers tr td:first-child").each(function(){        
    var textval = "<div class='bg' style='width:"+$(this).html()+"'>&nbsp;</div>";        
    $(this).html(textval);
   });
 });

演示

票数 2
EN

Stack Overflow用户

发布于 2014-08-06 06:54:46

你可以试试这样的东西

代码语言:javascript
复制
<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> 
票数 0
EN

Stack Overflow用户

发布于 2014-08-05 10:42:13

你可以用jQuery来做这个。条件格式(如Excel),请参见StackOverflow

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25136238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档