87,909
社区成员
发帖
与我相关
我的任务
分享
<style type="text/css">
div,ul,li{ margin:0; padding:0;}
ul,li{ list-style:none;position:relative;}
#dhp{ width:500px; }
#dhp li{ width:100px; height:150px; border:1px solid #ddd; padding:5px; float:left; margin-right:5px}
#dhp span{display:inline-block; width:49px; height:49px; position:absolute;top:5px;right:5px;background:url(dhp-stats.gif) no-repeat;}
#dhp span.gx{background:red;}
#dhp span.qj{background:green;}
#dhp span.xj{background:blue;}
</style>
<div id="container">
<div id="dhp">
<ul>
<li><span state="新加">1</span></li>
<li><span state="连载至40集">2</span></li>
<li><span state="完结">3</span></li>
</ul>
</div>
<div id="dhp">
<ul>
<li><span state="新加"></span>1</li>
<li><span state="连载至100集">2</span></li>
<li><span state="完结"></span>3</li>
</ul>
</div>
</div>
var dhp = document.getElementById("container");
var child=dhp.getElementsByTagName('span');
for(i = 0; i <child.length;i++){
var the = child[i];
for(var k = 0; k <= 1000; k++){
state = the.getAttribute('state');
if(state == '新加') the.className = 'xj';
if(state.indexOf('连载至' + [k] +'集') != -1) the.className = 'gx';
if(state == '完结') the.className = 'qj';
}
}
<style type="text/css">
div,ul,li{ margin:0; padding:0;}
ul,li{ list-style:none;position:relative;}
.dhp{ width:500px; }
.dhp li{ width:100px; height:150px; border:1px solid #ddd; padding:5px; float:left; margin-right:5px}
.dhp span{display:inline-block; width:49px; height:49px; position:absolute;top:5px;right:5px;background:url(dhp-stats.gif) no-repeat;}
.dhp span.gx{background:red;}
.dhp span.qj{background:green;}
.dhp span.xj{background:blue;}
</style>
<div class="dhp">
<ul>
<li><span state="新加">1</span></li>
<li><span state="连载至40集">2</span></li>
<li><span state="完结">3</span></li>
</ul>
</div>
<div class="dhp">
<ul>
<li><span state="新加"></span>1</li>
<li><span state="连载至100集">2</span></li>
<li><span state="完结"></span>3</li>
</ul>
</div>
<script type="text/javascript">
Array.prototype.inArray=function (value){for (var i=0;i<this.length;i++){if (this[i] == value){return true;}}return false};
function getElementsByClassName(className){
if(document.getElementByClassName){
return document.getElementByClassName(className)
}
var eles=document.getElementsByTagName("*"),elements=[];
for(var i=0;i<eles.length;i++){
var arr=eles[i].className.split(' ');
if(arr.inArray(className)){
elements.push(eles[i]);
}
}
return elements;
}
var dhp = getElementsByClassName("dhp");
for(i=0;i<dhp.length;i++){
var child=dhp[i].getElementsByTagName('span');
for(j = 0; j <child.length;j++){
var the = child[j];
for(var k = 0; k <= 1000; k++){
state = the.getAttribute('state');
if(state == '新加') the.className = 'xj';
if(state.indexOf('连载至' + [k] +'集') != -1) the.className = 'gx';
if(state == '完结') the.className = 'qj';
}
}
}
</script>