61,112
社区成员
发帖
与我相关
我的任务
分享
<!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>无标题文档</title>
<script src="jquery-1.8.3.min.js"></script>
<style>
.chk{height:22px; background:#f6f6f6;float:left; margin-left:5px; line-height:22px; vertical-align:middle;overflow:hidden; text-align:center;padding:0px 10px 0px 10px;border:1px solid #C99;font-size:12px;cursor:pointer}
.act{color:#F96;background:#fff;}
.chk input{ visibility:hidden; margin-left:-12px;}
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<div class="chk"><input type="checkbox" name="checkbox" value="0"/>西安</div>
<div class="chk"><input type="checkbox" name="checkbox" value="1"/>桂林</div>
<div class="chk"><input name="checkbox" type="checkbox" value="2"/>北京</div>
</form>
</body>
</html>
<script>
$(function(){
$(".chk").click(function(){
if($(this).find("input[name='checkbox']").attr("checked")!="checked"){
$(this).addClass("act");
$(this).find("input[name='checkbox']").attr("checked","checked");
}else{
$(this).removeClass("act");
$(this).find("input[name='checkbox']").removeAttr("checked");
}
})
})
</script>