|
实用小JAVA程序(二) |
|
你的主页有JAVA语句吗?JAVA是制作主页一些特效的最好语句,使用这些语句可以 使你的主页丰富多彩,但主页字节并没有很大的变化。
进入主页后当然是该出当天的时间和你正在使用什么浏览器浏览网页。代码如下: <sctipt language="Java Script"> <!--today=new Date(); var hours = today.getHours(); var minutes = today.getMinutes(); var seconds = today.getSeconds(); var timeValue = ""+ ((hours >12) ? hours -12 :hours); timeValue += ((minutes < 10) ? " <blank><font color=darkblue size=2>:0" : " <blank><font color=darkblue size=2>:") + minutes+""; <timeValue += (hours >= 12) ? " <font color=yellow size=2><i><b>PM</b></i></font>" : " <font color=darkblue size=2><i><b>AM</b></i></font>"; function initArray() {this.length=initArray.arguments.length for(var i=0;i<this.length;i++) this[i+1]=initArray.arguments[i] } var d=new initArray(" <font color=yellow size=2>星期日"," <font color=blue size=1>星期一"," <font color=blue size=2>星期二"," <font color=blue size=2>星期三"," <font color=blue size=2>星期四"," <font color=blue size=2>星期五"," <font color=GREEN size=2>星期六"); <document.write("<b><font color=black size=2> <font color=yellow size=2>非常欢迎你来到“猪娃工场”!</font>"," <font color=blue size=2>公元</font>",today.getYear()," <font color=blue size=2>年</font>",today.getMonth()+1," <font color=blue size=2>月</font>",today.getDate()," <font color=blue size=2>日</b></font>"," ",d[today.getDay()+1],""," <font color=yellow size=2>现在</b></font>",timeValue);// --> </sctipt> 该语句能在主页上加入一端简短的文字,并且能显示该时的年、月、日、时间等。 适当的更改一些中文字能达到个性化的效果。 除了能显示即时时间外,在浏览器中加上一些定时的问候能使浏览着有宾至如归的 感觉。代码如下: <script language="JavaScript"> <!-- now= new Date() hour=now.getHours() if (hour < 12) { time="你好!很高兴这么早就来探望我!" } else if (hour < 13) { time="吃过午饭没有?" } else if (hour < 18) { time="你在家吗?如果还没下班就该继续努力哦!" } else if (hour<23) { time="哟!就快到第二天了,还没睡呀?" } else if (hour < 4) { time="凌晨的空气清新吗?" } var scrtxt=time+"!"; var lentxt=scrtxt.length; var width=200; var count=0; var left=0; var abc=0; function scroll() {var txt="" ; var scroller=""; if (abc>0) { if ((abc%2)==1) { window.status=""; } else { window.status=scrtxt; } abc ++; if (abc==8)abc=0; } else { if (sount>0) { scroller=scrtxt.substring (0,count); txt=scrtxt.substring (count,count+2); } else {txt=scrtxt.subtring(0,2); } if ((width-left)>2) { left+=(width-left)/2; } else { left ++; } for (var i=0; i < (width-left); i + +) { scroller=scrooler + " "; } if (left>=width) { count+=2; left=count * 2; } if (count>=lentxt) { pos=count=0; abc=1; } scroller=scroller + txt; window.status=scroller; } setTimeout ("scroll ()",100); } scroll (); //--> </script> |