- 3/5
- 1
- 2
- 3
- 4
- 5
织梦DedeCMS视频教程买空间 租服务器 选网硕互联! 无忧站长工具,百度权重一键全查!
让你网页的某个地方随机显示一行文字,像每日一帖,名人名言等,由JS函数控制你事先准备好的文字库随机抽取一条显示出来,每次刷新网页都会有不种的文字。实际上这里用到了Javascript里的Math.random() 函数,不知道用法的正好也可以参考一下本代码。
<html> <head> <title>随机文字</title> </head> <body> <script language="JavaScript"> <!-- Hide var a = Math.random() + "" var rand1 = a.charAt(5) quotes = new Array quotes[1] = '文字一' quotes[2] = '文字二' quotes[3] = '文字三' quotes[4] = '文字四' quotes[5] = '文字五' quotes[6] = '文字六' quotes[7] = '文字七' quotes[8] = '文字八' quotes[9] = '文字九' quotes[0] = '文字十' var quote = quotes[rand1] //--> </script> <script language="JavaScript"> <!-- Hide document.write( quote ) //--> </script> </body> </html>