教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 js随机效果(从文本中随机选取字符串)

js随机效果(从文本中随机选取字符串)

发布时间:2014-10-10   编辑:jiaochengji.com
为大家介绍一个js实现的随机效果,实现从一段文本中随机取出字符串,并改变颜色。有需要的朋友,可以参考下。

代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function open () {return true;}
//-->
</SCRIPT>
<title>随机选取字符串并改变颜色_www.jbxue.com</title>
</head>
<BODY bgcolor=green text="white" bgcolor="green" link="yellow" vlink="yellow"  
alink="red">
<font color="yellow">
<SCRIPT LANGUAGE="JavaScript">
var speed = 20;
var fulltext;

if(navigator.appName == "Netscape")
document.write('<layer id="wds"></layer><br>');
if (navigator.appVersion.indexOf("MSIE") != -1)
document.write('<span id="wds"></span><br>');

function livetext()
{
fulltext="this is an example of random effect text"
var whichchar=Math.round((Math.random()*fulltext.length))
switch(whichchar){
case 0:
fulltext = '<font color="red">' + fulltext.substring(0,1) + '</font>' + fulltext.substring
(1,fulltext.length);
break;
case fulltext.length:
fulltext = fulltext.substring(0,fulltext.length-1) + '<font color="red">' + fulltext.substring
(fulltext.length-1,fulltext.length) + '</font>';
break;
default:
fulltext =  
fulltext.substring(0,whichchar) + '<font color="violet">' +
fulltext.substring(whichchar,whichchar+1) + '</font>' +
fulltext.substring(whichchar+1,fulltext.length);
break;
}
if(navigator.appName == "Netscape") {
size = "<font point-size='25pt'>";  
document.wds.document.write(size+'<center>' + fulltext + '</center></font>');
document.wds.document.close();
}
if (navigator.appVersion.indexOf("MSIE") != -1){
wds.innerHTML = '<center>' + fulltext + '</center><p>';
wds.style.fontSize='25px'
}
setTimeout("livetext()",speed);
}
livetext()
</script>
</font>
</body>
</html> 

您可能感兴趣的文章:
js随机效果(从文本中随机选取字符串)
php生成指定位数(长度)的随机字符串
php生成随机数的例子
php生成随机产生六位数密码的代码
php生成随机数字和字母的实例代码
用PHP生成随机数的函数
golang随机数
解析mysql实现随机查询的几种方法
mysql随机查询的经验分享
ASP生成不重复的随机数字

[关闭]
~ ~