Сообщение от drkrol
|
Класс span - это id.
|
лучше
data-id="140"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://randomcolor.llllll.li/randomColor.js"></script>
<style type="text/css">
body {
background:#F3F5F6
}
.date {
float: left;
width: 45px;
text-align: center;
z-index: 1;
position: relative;
height: 40px;
line-height: 40px;
color: #d0d0d0;
}
.cont {
padding: 40px;
background: white;
margin: 50px;
width: 530px;
height: 120px;
}
.busy {
width: 100%;
height: 100%;
position: absolute;
top: 0;
z-index: -1;
}
</style>
<title></title>
<script>
window.onload=function(){
var color = {};
[].forEach.call( document.querySelectorAll('.busy'), function(el) {
var id = el.querySelector('span').className,
rgb = color[id] || (color[id]=randomColor());
el.style.backgroundColor = rgb;
});
}
</script>
</head>
<body>
<div class="cont">
<div class="date">12</div>
<div class="date">13<div class='busy'><span class='140'></span></div></div>
<div class="date">14<div class='busy'><span class='140'></span></div></div>
<div class="date">15<div class='busy'><span class='140'></span></div></div>
<div class="date">16<div class='busy'><span class='141'></span></div></div>
<div class="date">17</div>
<div class="date">18<div class='busy'><span class='142'></span></div></div>
<div class="date">19<div class='busy'><span class='142'></span></div></div>
<div class="date">20<div class='busy'><span class='143'></span></div></div>
<div class="date">21<div class='busy'><span class='143'></span></div></div>
</div>
</body>
</html>