帮助随机代码...... [英] Help with random code...

查看:86
本文介绍了帮助随机代码......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想要做的是让b
)背景颜色随机改变5种不同的颜色。(更改

on页面加载)


2,)在

网页上的随机点中随机淡入和淡出10种不同的引号。有一个延迟计时器,所以他们不断变化,因为页面打开了。
。每次加载页面时都不随机。


如果有人可以提供帮助,那将是非常有用的,我已经尝试了很多

的东西,似乎无法得到我想要的东西。


它看起来如此简单却如此复杂......


从电子邮件中取出00' addy发送

Ok well what I am trying to do is have

1.) the background color to change randomly with 5 different colors.(change
on page load)

2,) 10 different quotes randomly fadeing in and out in random spots on the
webpage. with a delay timer on them, so they keep changing as the page is
open. Not random each time the page is loaded.

If anyone can help it would be greatly appreaciated, I have tried many of
things and just cant seem to get what I am looking for.

It seems so simple yet so complex...

take the 00''s out of email addy to send

推荐答案

病毒写道:
Virus wrote:
好吧我想做的就是< 1.)背景颜色随机改变5种不同的颜色。(更改页面加载时)

2,)10种不同的引号随机淡入淡出在
网页上的随机点。它们上有延迟计时器,所以当页面打开时它们会不断变化。每次加载页面时都不随机。

如果有人可以提供帮助,那将会有很大的影响,我已经尝试了很多东西,但似乎无法得到我想要的东西。

它看起来如此简单却如此复杂......

将00'的电子邮件发送出去发送
Ok well what I am trying to do is have

1.) the background color to change randomly with 5 different colors.(change
on page load)

2,) 10 different quotes randomly fadeing in and out in random spots on the
webpage. with a delay timer on them, so they keep changing as the page is
open. Not random each time the page is loaded.

If anyone can help it would be greatly appreaciated, I have tried many of
things and just cant seem to get what I am looking for.

It seems so simple yet so complex...

take the 00''s out of email addy to send



将您的值放在数组中...

var quotes_array = new Array();


您可以填充数组...

quotes_array [0] ="这是一个引用" ;;


现在,你可以获得一个1到10之间的随机数:

var rand = Math.floor(Math.random()* 10)+ 1;


您可以使用该随机数作为数组的索引:

alert(quotes_array [rand]);


这有帮助吗?

Brian


Put your values in an array...
var quotes_array = new Array();

You can populate the array...
quotes_array[0] = "This is a quote";

Now, you can get a random number, between 1 and 10:
var rand = Math.floor(Math.random() * 10) + 1;

You can use that random number as an index to the array:
alert(quotes_array[rand]);

Does that help?
Brian


Brian Genisio说:
Brian Genisio said:

病毒写道:

Virus wrote:
好吧我正在尝试做的是

1.)背景颜色随机改变5种不同的颜色。(更改页面加载时)

2,)10个不同的引号随机淡入和淡出
网页。它们上有延迟计时器,所以当页面打开时它们会不断变化。每次加载页面时都不随机。

如果有人可以提供帮助,那将会有很大的影响,我已经尝试了很多东西,但似乎无法得到我想要的东西。

它看起来如此简单却如此复杂......

将00'的电子邮件发送出去发送
Ok well what I am trying to do is have

1.) the background color to change randomly with 5 different colors.(change
on page load)

2,) 10 different quotes randomly fadeing in and out in random spots on the
webpage. with a delay timer on them, so they keep changing as the page is
open. Not random each time the page is loaded.

If anyone can help it would be greatly appreaciated, I have tried many of
things and just cant seem to get what I am looking for.

It seems so simple yet so complex...

take the 00''s out of email addy to send



将你的值放在数组中......
var quotes_array = new Array();

你可以填充数组...
quotes_array [0] =" ;这是一个引用;

现在,你可以得到一个1到10之间的随机数:
var rand = Math.floor(Math.random()* 10)+ 1 ;

您可以使用该随机数作为数组的索引:
alert(quotes_array [rand]);


Put your values in an array...
var quotes_array = new Array();

You can populate the array...
quotes_array[0] = "This is a quote";

Now, you can get a random number, between 1 and 10:
var rand = Math.floor(Math.random() * 10) + 1;

You can use that random number as an index to the array:
alert(quotes_array[rand]);




你会希望随机数的范围从零到

到一个小于数组中元素的数量,

这简单地说:


var rand = Math.floor(Math.random()* quotes_array.length);



You''ll want the random number to range from zero up
to one less than the number of elements in the array,
which is simply:

var rand = Math.floor(Math.random()*quotes_array.length);


Brian Genisio <峰; br ********** @ yahoo.com>在留言中写道

news:40 ******** @ 10.10.0.241 ...

< snip>
"Brian Genisio" <Br**********@yahoo.com> wrote in message
news:40********@10.10.0.241...
<snip>
Put您在数组中的值...
var quotes_array = new Array();

您可以填充数组...
quotes_array [0] ="这是一个报价英寸;


或数组文字: -


var quotes_array = [

"这是一个引用,

" This is quote 2",

" This is quote 3",

" This is quote 4"

];

现在,您可以获得1到10之间的随机数:
var rand = Math.floor(Math.random()* 10)+ 1 ;


或者: -


var rand = Math.ceil(Math.random()* 9);

但javascript数组基于零。

您可以使用该随机数作为数组的索引:
alert(quotes_array [rand]);
Put your values in an array...
var quotes_array = new Array();

You can populate the array...
quotes_array[0] = "This is a quote";
Or an Array literal:-

var quotes_array = [
"This is a quote",
"This is quote 2",
"This is quote 3",
"This is quote 4"
];
Now, you can get a random number, between 1 and 10:
var rand = Math.floor(Math.random() * 10) + 1;
Or:-

var rand = Math.ceil(Math.random() * 9);

But javascript arrays are zero based.
You can use that random number as an index to the array:
alert(quotes_array[rand]);




所以基于数组长度的随机数将保存

两段代码失效: -

var rand = Math.floor(Math.random()* quotes_array.length);


从数组中随机选择有合理的概率

重复选择相同的元素。

随机抽取数组内容然后循环遍历

结果可能会更好。


Richard 。



So basing the random number on the length of the array would save the
two pieces of code getting out of step:-

var rand = Math.floor(Math.random() * quotes_array.length);

Randomly selecting from an Array has a reasonable probability of
repeatedly selecting the same element. It would probably be better to
randomly shuffle the contents of the array and then loop through the
results sequentially.

Richard.


这篇关于帮助随机代码......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆