求一个随机显示文字的HTML页面.

html-css011

求一个随机显示文字的HTML页面.,第1张

<html><head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">

<title>阿里西西网页特效演示,文本随机显示</title>

</head><body>

刷新看看<script language="JavaScript">

<!-- Hide

var a = Math.random() + ""

var rand1 = a.charAt(5)

quotes = new Array

<!-- 修改下面的文字为你需要的文字-->

quotes[1] = '文本内容1'

quotes[2] = '文本内容2'

quotes[3] = '文本内容3'

quotes[4] = '文本内容4'

quotes[5] = '文本内容5'

quotes[6] = '文本内容6'

quotes[7] = '文本内容7'

quotes[8] = '文本内容8'

quotes[9] = '文本内容9'

quotes[0] = '文本内容10'

var quote = quotes[rand1]

//-->

</script>

<script language="JavaScript">

<!-- Hide

document.write(quote)

// -->

</script></body></html>试试看我已经做过测试

使用js实现

html 并不能实现该方法

js代码

<script language="javascript">

var shuzu

shuzu=new Array("you","i","he")

var number=Math.floor(Math.random()*2)

document.write (shuzu[number])

</script>

shuzu 为定义的数组,你可以按照样式添加

Math.random()返回0和1间(包括0,不包括1)的一个随机数

Math.floor(n)返回小于等于n的最大整数。

为什么*2 是因为上面数组只有3个值 因为数组时从0开始,所以乘2

Math.floor(Math.random()*8+1))//0~9之间的,就是1-8

x 是你想要的条数

<script language="JavaScript">

<!-- Hide

var rand1 = Math.floor(Math.random()*x+1))

quotes = new Array

quotes[1] = '123123'

quotes[2] = '12322222'

quotes[3] = '655555555555'

quotes[4] = '666666666'

quotes[5] = '7777777'

quotes[6] = '8888'

quotes[7] = '999'

quotes[8] = '0000'

quotes[9] = '222'

quotes[0] = '111'

....

quotes[x] = '11145345'

var quote = quotes[rand1]

//-->

</script>

应该可以,没尝试~~~