您的位置:首页 > Web前端 > JQuery

jquery的table隔行变色、复选框的选择变色

2012-03-26 22:07 288 查看
<!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>parent</title>

<style>

.even{

background-color:#0FF;

}

.odd{

background-color:#F9F;}

.selected{

background:#CCC;

}

.selected1{

background-color:#99F;

}

</style>

<script src="../jquery/jquery-1.7.1.js"></script>

<script>

$(document).ready(function(){

$("tr:even").addClass("even");

$("tr:odd").addClass("odd");

$("input[type=checkbox]").hover(function(){

$(this).parents("tr").toggleClass("selected1");

});

$("input[type=checkbox]").click(function (){

// alert("ddd");

// if($("input[type=checkbox]:checked")){

//alert($("input[type=checkbox]:checked").length);

$(this).parents("tr").toggleClass("selected");

//}else{

//$(this).parent("tr").removeClass("selected");

//}

});

// $(this).toggleClass("selected");

});

</script>

</head>

<body>

<table width="500" border="1">

<tr>

<td> </td>

<td>姓名</td>

<td>班级</td>

<td>E-mail</td>

</tr>

<tr>

<td><input type="checkbox" class="ck" name="ck" /></td>

<td>马丹玲</td>

<td>php</td>

<td>1223312</td>

</tr>

<tr>

<td><input type="checkbox" class="ck" name="ck" /></td>

<td>聂彦池</td>

<td>php</td>

<td>3574789</td>

</tr>

<tr>

<td><input type="checkbox" class="ck" name="ck" /></td>

<td>李楠</td>

<td>php</td>

<td>345645</td>

</tr>

<tr>

<td><input type="checkbox" class="ck" name="ck" /></td>

<td>齐小松</td>

<td>php</td>

<td>54765</td>

</tr>

<tr>

<td><input type="checkbox"class="ck" name="ck" /></td>

<td>马浩鹏</td>

<td>php</td>

<td>3769088</td>

</tr>

<tr>

<td><input type="checkbox" class="ck" name="ck" /></td>

<td>宋凯</td>

<td>php</td>

<td>3554853</td>

</tr>

<tr>

<td><input type="checkbox" name="ck" /></td>

<td>丁延</td>

<td>php</td>

<td>46485</td>

</tr>

</table>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: