<script LANGUAGE="JavaScript">
classran = Math.floor(Math.random() * 3);
if (classran ==0){
a = Math.floor(Math.random() * 30);
document.write(a);
}
else (classran ==1){
b = Math.floor(Math.random() * 80);
document.write(b);
}
else if (classran ==2){
c = Math.floor(Math.random() * 20);
document.write(c);
}
else (classran ==3){
d = Math.floor(Math.random() * 83);
document.write(d);
}
</script>还是不行啊!
classran = Math.floor(Math.random() * 3);
if (classran ==0){
a = Math.floor(Math.random() * 30);
document.write(a);
}
else (classran ==1){
b = Math.floor(Math.random() * 80);
document.write(b);
}
else if (classran ==2){
c = Math.floor(Math.random() * 20);
document.write(c);
}
else (classran ==3){
d = Math.floor(Math.random() * 83);
document.write(d);
}
</script>还是不行啊!
<script LANGUAGE="JavaScript">
var classran;
classran= Math.floor(Math.random()*3);
alert(classran);if (classran ==0)
{
a = Math.floor(Math.random()*30);
alert(a);
}
else (classran ==1)
{
b = Math.floor(Math.random()*80);
alert(b);
}</script>
<head><script LANGUAGE="JavaScript">
var classran;
classran= Math.floor(Math.random()*3);if (classran ==0)
{
a = Math.floor(Math.random()*30);
document.write('<BODY BACKGROUND="/image/yudian/yudian ('+a+').jpg">');
}
else (classran ==1)
{
b = Math.floor(Math.random()*80);
document.write('<BODY BACKGROUND="/image/blue/blue ('+b+').jpg">');
}
else if (classran ==2)
{
c = Math.floor(Math.random() * 20);
document.write('<BODY BACKGROUND="/image/flower/flower ('+c+').jpg">');
}
else (classran ==3)
{
d = Math.floor(Math.random() * 83);
document.write('<BODY BACKGROUND="/image/kagaya/kagaya ('+d+').jpg">');
</script>
</head>
<body>
</body>
</html>
全部代码!你看看吧!
目的是每次刷新随机更换背景。
<head><script LANGUAGE="JavaScript">
var classran;
classran= Math.floor(Math.random()*3);if (classran ==0)
{
a = Math.floor(Math.random()*30);
document.write('<BODY BACKGROUND="image/yudian/yudian ('+a+').jpg">');
}
else if (classran ==1)
{
b = Math.floor(Math.random()*80);
document.write('<BODY BACKGROUND="image/blue/blue ('+b+').jpg">');
}
else if (classran ==2)
{
c = Math.floor(Math.random() * 20);
document.write('<BODY BACKGROUND="image/flower/flower ('+c+').jpg">');
}
else
{
d = Math.floor(Math.random() * 83);
document.write('<BODY BACKGROUND="image/kagaya/kagaya ('+d+').jpg">');
</script>
</head>
<body>
</body>
</html>
问题在if和else if
这两个怎么用?