熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

用JavaScript實現一些隨機事件

2022-06-13   來源: JSP教程 
隨機廣告

<SCRIPT LANGUAGE=JavaScript>
<! Begin
var how_many_ads = ;
var now = new Date()
var sec = nowgetSeconds()
var ad = sec % how_many_ads;
ad +=;
if (ad==) {
txt=The Worlds Largest Online Bookstore ;
url=;
alt=;
banner=_Bangif;
width=;
height=;
}
if (ad==) {
txt=Palm III by Com in stock!;
url=;
alt=;
banner=_Bangif;
width=;
height=;
}
if (ad==) {
txt=Find it at ;
url=;
alt=;
banner=_Bangif;
width=;
height=;
}
documentwrite(<center>);
documentwrite(<a href=\ + url + \ target=\_top\>);
documentwrite(<img src=\ + banner + \ width=)
documentwrite(width + height= + height + );
documentwrite(alt=\ + alt + \ border=>
);
documentwrite(<small> + txt + </small></a>);
documentwrite(</center>);
// End >
</SCRIPT>
隨機背景顏色

<HTML>
<HEAD>
<TITLE>Random Background</TITLE>

<SCRIPT LANGUAGE=JavaScript>
<!
function backcolor(form) {
temp =
for (var i = ; i < ; i++) {
temp = lor[i]value
if (lor[i]checked){ documentbgColor = temp }
  }
}
function randombackground() {
documentbgColor = getColor()
}
function getColor(){
currentdate = new Date()
backgroundcolor = currentdategetSeconds()
if (backgroundcolor > )
backgroundcolor = backgroundcolor
else if (backgroundcolor > )
backgroundcolor = backgroundcolor
else if (backgroundcolor > )
backgroundcolor = backgroundcolor
if (backgroundcolor == )
return olive;
else if (backgroundcolor == )
return teal;
else if (backgroundcolor == )
return red;
else if (backgroundcolor == )
return blue;
else if (backgroundcolor == )
return maroon;
else if (backgroundcolor == )
return navy;
else if (backgroundcolor == )
return lime;
else if (backgroundcolor == )
return fuschia;
else if (backgroundcolor == )
return green;
else if (backgroundcolor == )
return purple;
else if (backgroundcolor == )
return gray;
else if (backgroundcolor == )
return yellow;
else if (backgroundcolor == )
return aqua;
else if (backgroundcolor == )
return black;
else if (backgroundcolor == )
return white;
else if (backgroundcolor == )
return silver;
}
// End >
</SCRIPT>
</HEAD>

<BODY BGCOLOR=#ffffff vlink=#ff>

<CENTER>
<FORM>
<input type=button value=隨機背景顏色 onClick=randombackground()>
</FORM>
</CENTER>

</body></html>

隨機背景圖案

<HTML>
<HEAD>
<TITLE>Random Images</TITLE>

<SCRIPT LANGUAGE=JavaScript>

today=new Date();
jran=todaygetTime();
var number = ;
var random_number=;
var image=;
var text_color=;

ia=;
ic=;
im=;
jran = (jran*ia+ic) % im;
random_number = Mathceil( (jran/(im*)) *number);

if (random_number==) {
text_color=;
image=bggif;
}
if (random_number==) {
text_color=;
image=bgjpg;
}
if (random_number==) {
text_color=;
image=bggif;
}
// End >
</SCRIPT>
</HEAD>

<SCRIPT LANGUAGE=JavaScript>
<! Begin
documentopen();
documentwrite(<BODY BACKGROUND=+image+ TEXT=+text_color+ vlink=#ff>);
documentwrite(<CENTER></CENTER>);
// End >
</SCRIPT>

<FORM>
<INPUT TYPE=button VALUE=Reload Page onClick=windowlocation=>
</FORM>
<SCRIPT LANGUAGE=JavaScript>
<! Begin
documentwrite(<CENTER><FONT SIZE= color=red>Background Image: (+image+)</FONT></CENTER>);
// End >
</SCRIPT>

</body></html>
隨機圖案

把以下代碼放在<head></head>之間
<script language=JavaScript>
a =
var slump = Mathrandom();
var talet = Mathround(slump * (a))+;
function create() {
    thissrc =
    thisborder =
thisalt =
}

b = new Array()
for(var i=; i<=a; i++) { b[i] = new create() }

b[]src  = resetgif
b[]border =
b[]alt  =

b[]src  = backgif
b[]border =
b[]alt  =

b[]src  = iegif
b[]border =
b[]alt  =

b[]src  = netscapegif
b[]border =
b[]alt  =

var visa = ;
visa += <img src=+b[talet]src+ border=+ alt=+b[talet]alt+>;
</SCRIPT>

把以下代碼放在HTML文件任意地方
<script language=JavaScript>
<! Hide this script from old browsers
documentwrite(visa)
// >
</script>
隨機播放MIDI音樂

把以下代碼放在<head></head>之間
<script language=JavaScript>
<!Hide from non JavaScript browsers
am =
var ran = Mathrandom();
var talet = Mathround(ran * (am))+;
function create() {
    thissrc =
}

c = new Array()
for(var i=; i<=am; i++) { c[i] = new create() }

c[]src  = hhmid
c[]src  = hhmid
c[]src  = hhmid
c[]src  = hhmid
c[]src  = hhmid
var vismid = ;

vismid += <embed src=+c[talet]src+ width= height=+ autostart=true+ loop=+>;
//>
</SCRIPT>
把以下代碼放在<body></body>之間
<script language=JavaScript>
<!Hide from non JavaScript browsers
documentwrite(vismid);
//>
</script>
隨機文本

把以下代碼放在<head></head>之間
<script language=JavaScript>
<! Hide
var a = Mathrandom() +
var rand = acharAt()
quotes = new Array
quotes[] = MESSAGE #
quotes[] = MESSAGE #
quotes[] = MESSAGE #
quotes[] = MESSAGE #
quotes[] = MESSAGE #
quotes[] = MESSAGE #
quotes[] = MESSAGE #
quotes[] = MESSAGE #
quotes[] = MESSAGE #
quotes[] = MESSAGE #
var quote = quotes[rand]
// >
</script>
把以下代碼放在HTML文件任意地方
<script language=JavaScript>
<! Hide
documentwrite(<i> + quote + </i>)
// >
</script>
隨機連接

把以下代碼放在<head></head>之間
<script language=JavaScript>
<!Hide from non JavaScript browsers
an =
var ran = Mathrandom();
var talet = Mathround(ran * (an))+;
function create() {
    thissrc =

}

b = new Array()
for(var i=; i<=an; i++) { b[i] = new create() }

b[]src  = <a >
b[]src  = <a >
b[]src  = <a >
b[]src  = <a >
b[]src  = <a >
var vis = ;
vis += b[talet]src;
//>
</SCRIPT>
把以下代碼放在<body></body>之間
<script language=JavaScript>
<!Hide from non JavaScript browsers
documentwrite(vis+random link+</a>);
//>
</SCRIPT>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19481.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.