<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>each</title>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(e) {
$('tr:first').css("background-color","#FF0");
$('tr:gt(0):odd').css("background-color","#0FF");
});
//$.each(数组,function(K,V))
var color =['gold','yellow','orange','blue'];
$.each(color,function(k,v){
console.log(k+"---"+v);
});
//遍历对象
var cat ={'name':"yellow",'color':"orange",'climb':function(){
console.log('8520');
}};
$.each(cat,function(k,v){
console.log(k+"---"+v);
});
window.onload = function(){
$("li").each(function(k,v){
/*console.log(k+"---"+v);
if(k==1){
// v.style.color="blue";
$(v).css("background-color",'lightgreen');
}else if(k==2){
$(v).css("background-color",'blue');
}*/
//console.log(this);
var color =['gold','yellow','orange','blue'];
$(this).css('background-color',color[Math.floor(Math.random()*4)]);
});
}
</script>
<style type="text/css">
</style>
</head>
<body>
<ul>
<li>巷道</li>
<li>北京</li>
<li>诗经</li>
<li>物流</li>
</ul>
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>each</title>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(e) {
$('tr:first').css("background-color","#FF0");
$('tr:gt(0):odd').css("background-color","#0FF");
});
//$.each(数组,function(K,V))
var color =['gold','yellow','orange','blue'];
$.each(color,function(k,v){
console.log(k+"---"+v);
});
//遍历对象
var cat ={'name':"yellow",'color':"orange",'climb':function(){
console.log('8520');
}};
$.each(cat,function(k,v){
console.log(k+"---"+v);
});
window.onload = function(){
$("li").each(function(k,v){
/*console.log(k+"---"+v);
if(k==1){
// v.style.color="blue";
$(v).css("background-color",'lightgreen');
}else if(k==2){
$(v).css("background-color",'blue');
}*/
//console.log(this);
var color =['gold','yellow','orange','blue'];
$(this).css('background-color',color[Math.floor(Math.random()*4)]);
});
}
</script>
<style type="text/css">
</style>
</head>
<body>
<ul>
<li>巷道</li>
<li>北京</li>
<li>诗经</li>
<li>物流</li>
</ul>
</body>
</html>