62,074
社区成员
发帖
与我相关
我的任务
分享
$('#table1>tr>td').each(function(i){ //遍历表格的子的td,不遍历嵌套的table td
if(i%3 == 0 || i%3 == 1){ //i%3=0表示第一列 i%3=1表示第二列 3是列数,我这里是个三列的
// $(this).css("float","left");
$(this).addClass("aa");
}
});
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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 runat="server">
<title>无标题页</title>
<style type="text/css">
.aa
{
float:left;
}
</style>
<script src="jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#content").find('div').each(function(i){ //遍历表格的单元格
if(i%3 == 0 || i%3 == 1){ //i%3=0表示第一列 i%3=1表示第二列 3是列数,我这里是个三列的
// $(this).css("float","left");
$(this).addClass("aa");
alert($(this).text());
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="content">
<div>1</div><div>2</div><div>3</div>
<div>1</div><div>2</div><div>3</div>
<div>1</div><div>2</div><div>3</div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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 runat="server">
<title>无标题页</title>
<style type="text/css">
.aa
{
float:left;
}
</style>
<script src="jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$('table').find('td').each(function(i){ //遍历表格的单元格
if(i%3 == 0 || i%3 == 1){ //i%3=0表示第一列 i%3=1表示第二列 3是列数,我这里是个三列的
// $(this).css("float","left");
$(this).addClass("aa");
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table border="1" width="100" style="text-align:center;align:center;">
<tr>
<td>1</td><td>2</td><td>3</td>
</tr>
<tr>
<td>1</td><td>2</td><td>3</td>
</tr>
<tr>
<td>1</td><td>2</td><td>3</td>
</tr>
</table>
</form>
</body>
</html>