<style type="text/css">
.box {
width:100px;
height:50px;
}
.red-bg{
background:red;
}
.green-bg{
background:green;
}
</style>
</head>
<body>
<div class="box red-bg">
<input type="checkbox" />
</div>
</body>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("input").click(function(){
var class_all=$("div").attr("class");
var obj_div=$("div");
if(class_all=="box red-bg"){
obj_div.removeClass("red-bg").addClass("green-bg");
}else{
obj_div.removeClass("green-bg").addClass("red-bg")
};
})
})
</script>
时间: 2024-10-11 06:12:34