日期:2014-05-16 浏览次数:20454 次
<div id="container">
<div class="css1">111</div>
<div class="css2">222</div>
<div class="css3">333</div>
</div>
<script type="text/javascript">
window.onload = function(){
var container = document.getElementById('container');
var divs = container.getElementsByTagName('div');
var len = divs.length;
for(var i=0;i<len;i++){
divs[i].onmouseout = function(){
var classes = this.className;
classes = classes.split(' ');
var len = classes.length,i=len-1;
for(;i>=0;i--){
if(classes[i]=='css4'){
classes.splice(i,1);
}
}
this.className = classes.join(' ');
}
divs[i].onmouseover= function(){
this.className += ' css4';
}
}
}
</script>
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>无标题文档</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$(".css1,.css2,.css3").mouseover(function(e) {
$(this).addClass("css4")
}).mouseout(function(e) {
$(this).removeClass("css4")
});;
});
</script>
<style type="text/css">
.css1 {
background-color: #CCC;
}
.css2 {
background-color: #abc;
}
.css3 {
background-color: #cba;
}
.css4 {