javascript

位置:IT落伍者 >> javascript >> 浏览文章

用JavaScript实现一些随机事件


发布日期:2024年03月02日
 
用JavaScript实现一些随机事件
随机广告

<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>

<INPUTTYPE=button VALUE=ReloadPage 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>               

上一篇:Javascript中CTRL+回车提交表单

下一篇:格式化json日期格式对象