jquery交替变换颜色的三种方法 实例代码
<!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>even and odd</title>
<script type="text/javascript" src="jquery-1.4.4.js"></script>
<script type="text/javascript" language="javascript">
$(function(){
alert("第一种");
$("tbody tr:even").css("background-color", "red");
$("tbody tr:odd").css("background-color", "yellow");
alert("第二种");
$("tbody tr").each(function (index){
alert(index);
if(0 == index%2)
{
$(this).css("background-color", "blue");
}
if(1 == index%2)
{
$(this).css("background-color", "green");
}
});
alert("第三种");
rows = document.getElementsByTagName("tr");
var length = rows.length;
for(var i=0; i< length;i++){
alert(i);
if(0==i%2){
rows[i].style.backgroundColor="#ffff00";
}else
{
rows[i].style.backgroundColor="#0000FF";
}
}
});
</script>
</head>
<body>
<table border="1">
<tbody >
<tr> <td>aaa</td> <td>aaa</td> <td>aaa</td></tr>
<tr> <td>bbb</td> <td>bbb</td> <td>bbb</td></tr>
<tr> <td>aaa</td> <td>aaa</td> <td>aaa</td></tr>
<tr> <td>bbb</td> <td>bbb</td> <td>bbb</td></tr>
<tr> <td>aaa</td> <td>aaa</td> <td>aaa</td></tr>
<tr> <td>bbb</td> <td>bbb</td> <td>bbb</td></tr>
</tbody>
</table>
</body>
</html>
相关文章
基于jquery的一个OutlookBar类,动态创建导航条
初学jquery,如有错误,请高手们指出想看效果及完整代码的可以下载rar包2010-11-11
jQuery获取访问者IP地址的方法(基于新浪API与QQ查询接口)
这篇文章主要介绍了jQuery获取访问者IP地址的方法,实例分析了jQuery基于新浪API与QQ查询接口获取来访者IP的相关参数传递与数据处理技巧,需要的朋友可以参考下2016-05-05
修改jQuery.Autocomplete插件 支持中文输入法 避免TAB、ENTER键失效、导致表单提交
jQuery.Autocomplete 是jquery的流行插件,能够很好的实现输入框的自动完成(autocomplete)、建议提示(input suggest)功能,支持ajax数据加载。2009-10-10
jQuery使用load()方法载入另外一个网页文件内的指定标签内容到div标签的方法
这篇文章主要介绍了jQuery使用load()方法载入另外一个网页文件内的指定标签内容到div标签的方法,涉及jQuery中load方法的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下2015-03-03


最新评论