<!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>
$('td:eq(i)')这个地方不可以传入i变量,因为$(selector)是在当前的HTML Document中通过selector查找DOM元素,传入的i并不能通过for循环将值传入,你可以通过传入常量试一下就明白了