jquery 遍历数组 改变每一个数组的css

html-css011

jquery 遍历数组 改变每一个数组的css,第1张

你是要显示隐藏吧

$(function () {

var type = $(":radio")

var content = $("#content td")

type.click(function () {

content.hide()

$(content[type.index($(this))]).show()

})

})

<!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/htmlcharset=utf-8" />

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>

<title>无标题文档</title>

<script>

$(function(){

$('#mydiv div').each(function(i){

$(this).css({'height':'30px','background-color' : '#ddd'})

if(i==3)//如果遍历到第四个时候

{$(this).css({'height':'30px','background-color' : 'yellow'})}

})

})

</script>

</head>

<body>

<div id="mydiv" style="width:200px">

<div>1</div>

<div>2</div>

<div>3</div>

<div>4</div>

<div>5</div>

</div>

</body>

</html>