<!DOCTYPE html>
<html>
<head>
<script src="https://www.jq22.com/jquery/jquery-1.7.1.js"></script>
<script src="js/jquery.qrcode.min.js"></script>
<style type="text/css">
.color1
{
bgcolor="#9dc6eb"
border-radius: 25px;
border: 2px solid #73AD21;
padding: 2px;
}
.color2
{
bgcolor="#9dc6eb"
border-radius: 25px;
border: 2px solid #73AD21;
padding: 2px;
}
.color3
{
bgcolor="#f8c471"
border-radius: 25px;
border: 2px solid #73AD21;
padding: 2px;
}
.color4
{
bgcolor="#b9a3ef"
border-radius: 25px;
border: 2px solid #73AD21;
padding: 2px;
}
.color5
{
bgcolor="#fdb1ca"
border-radius: 25px;
border: 2px solid #73AD21;
padding: 2px;
}
</style>
</head>
<body>
<span class="color_span">随机颜色的Span1</span>
<span class="color_span">随机颜色的Span2</span>
<span class="color_span">随机颜色的Span3</span>
<span class="color_span">随机颜色的Span4</span>
<span class="color_span">随机颜色的Span5</span>
<span class="color_span">随机颜色的Span6</span>
<span class="color_span">随机颜色的Span7</span>
<script>
$(".color_span").each(function(i, obj){
var j = Math.floor(Math.random()*5);
switch(j){
case 0:
$(this).addClass("color1");
break;
case 1:
$(this).addClass("color2");
break;
case 2:
$(this).addClass("color3");
break;
case 3:
$(this).addClass("color4");
break;
default:
$(this).addClass("color5");
break;
}
})
</script>
</body>
</html>
这段代码无效呢~
还有 不希望按这个顺序给颜色 而是这5种颜色随机给 怎么做呢?