1.会走的时钟:
function myDate(){
var date =new Date()
var hour =date.getHours()
varminute=date.getMinutes()
varsecond=date.getSeconds()
if(hour<10)hour="0"+hour
if(minute<10)minute="0"+minute
if(second<10)second="0"+second
time1.innerHTML=hour+":"+minute+":"+second //要用innerHTML这个对象,绝对不能用document.write()后者是直接歇过来,没有动态的走的过程,不然后面那个setTimeout就没有用了。至于为什么是960不是1000我还没搞清楚。
varctimer=setTimeout('myDate()',960);
}
2.变色的菜单:
很简单,直接用onmouseover,onmouseout两个内置对象调用两个函数,函数用来改变颜色;
<html><head>
<script>
function color1(object){//改变颜色的方法,直接改变样式的背景颜色
object.style.background="#ffffcc"
}
functioncolor2(object){
object.style.background="#99ffff"
}
</script></head><body>
<tablealign="center" style="background:none rgb(122,122,122)">
<tr><tdwidth="15%" align="center" style="background: none repeat scroll 0% 0% rgb(153, 255,255);" οnmοuseοver="color1(this)"οnmοuseοut="color2(this)"><a href="#">XXX</a></br>
//此处直接用onmouseover,onmouseout调用设定的方法即可。这里有部分样式的设置:align,width
Style中的background: rgb()这种写法要学会~~
<tr><tdwidth="15%" align="center"οnmοuseοver="color1(this)" οnmοuseοut="color2(this)"style="background: none repeat scroll 0% 0% rgb(153, 255, 255);">
<ahref="#" >gaowenjian</a></br>
</td></tr>
</body></html>
3.传下拉菜单的值:
<selectname="select"οnchange="check(this.options[this.selectedIndex].value)">//这是重点!仔细看看就是document的使用,非常方便!
<optionselected>选择</option>
<optionvalue="gaowenjian">XXXX</option>
<optionvalue="gaowen">gaowenjian</option>
</select>
4.计算倒计时
<script>
Vardate1=new Date("12/1/2012")
Var now =new Date()
Var s = "距离还有几天"
Var distance =date1.getTime()-now.getTime();
Var day = Math.floor(distance/(1000*60*60*24))//关键的地方,计算到底有几天!
If(day>1)
Document.write("")
Elseif(day==1)
Document.write()
Elseif(day==0)
Document.write()
Else
Document.write()
</scrpit>
5.滚动菜单栏。整体来说,不难写,只是刚刚接触,对script的使用有点陌生,此处的for循环内部的i一开始写的int I 结果就出错了!!小心!脚本中没有类型一说!!
<script>
Varindex=2;
Link=newArray(1)
Text=newArray(1)
Link[0]='1'
Link[1]='1'
Text[0]='2'
text[0]='2'
Document.write("<marquee width='150' direction='up'scrolldelay='100' >")//直接用这个标签就可以实现滚动惨淡栏!!
For(i=0;i<index;I==){//循环把菜单栏内的东西显示出来~
Document.write("<imgsrc='XX' width='XXX'> <ahref=''+link[i]+">"+text[i]);
Document.write("</a><br>");}
Document.write("</marquee>");
</script>