想给table每列分别添加一个样式,可是addClass没反应
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
<link href="css/myStyle.css"/>
<style>
.position
{
width:87px;
height:37px;
background:red;
}
.AQI
{
width:30px;
}
.category
{
width:30px;
}
.PP
{
width:73px;
background:#0C3;
}
</style>
</head>
<body>
<table border="1" cellspacing="0">
<tr>
<td>sfe</td><td>fe</td><td>gfefe</td><td>gfefe</td>
</tr>
<tr>
<td>sfe</td><td>fe</td><td>gfefe</td><td>gfefe</td>
</tr>
<tr>
<td>sfe</td><td>fe</td><td>gfefe</td><td>gfefe</td>
</tr>
</table>
<script type="text/javascript">
$(document).ready(function() {
var len = $('td').length;
for(var i=0;i<len;i+=4)
$('td:eq(i)').addClass('position');
for(var j=1;j<len;j+=4)
$('td:eq(j)').addClass('AQI');
for(var k=2;k<len;k+=4)
$('td:eq(k)').addClass('category');
for(var l=3;l<len;l+=4)
$('td:eq(l)').addClass('PP');
});
</script>
</body>
</html>