|
√ Google adsense申请技巧 √ 本站核心代理域名注册主机业务
√ 快速发布你的买卖域名买卖网站信息
√ 1元注册 cn域名
√ 站长每日新闻导读 √ ·推荐万网空间¥120元 150m √ 站长网:站长必上的网站 √ 网站联盟大全 √ 本站代理万网域名55空间120元 |
<body>
hello,
<script language="vbscript">
<!--
dim thishour
thishour=hour(time)
if thishour<=12 then
document.bgcolor="red"
document.fgcolor="black"
document.write("上午好!")
else
if thishour<=18 then
document.bgcolor="blue"
document.fgcolor="white"
document.write("下午好!")
else
document.bgcolor="green"
document.fgcolor="yellow"
document.write("晚上好!")
end if
end if
-->
</script>
本页的作用是根据不同时间显示不同颜色和欢迎信息。
</body>
以上程序很简单吧,只要能认识英文就会懂程序(我是这么理解的:)
先把现在的小时提交出来:hour(time);
然后和12比较判断,如果<=12,肯定是上午了,否则就是下午和晚上;
否则里面继续条件判断,如果时间再<=18的话,那肯定就是下午了;
最后,不用说,瞎子猜猜也知道是晚上了:)
有关上一程序中的document.bgcolor就是文档的背景色,document.fgcolor就是文档的前景色(文字色),下一程序是动态改变背景颜色的。
<script language="vbscript">
<!--
sub setbgcolor(bcolor)
document.bgcolor=bcolor
end sub
-->
</script>
<form>
<input type="radio" name="color" onclick=setbgcolor("red")>red<br>
<input type="radio" name="color" onclick=setbgcolor("green")>green<br>
<input type="radio" name="color" onclick=setbgcolor("blue")>blue<br>
<input type="radio" name="color" onclick=setbgcolor("yellow")>yellow<br>
<input type="radio" name="color" onclick=setbgcolor("gray")>gray<br>
</form>
有关条件选择结构的嵌套再show出一个表单检测的程序
<html><head><title>abc</title>
<script language="vbscript">
<!--
sub btnsubmit_onclick
if form1.name.value<>"" then
if form1.addr.value<>"" then
if form1.email.value<>"" then
if instr(form1.email.value,"@")<>0 and instr(form1.email.value,".")<>0 then
form1.submit
else
alert"email error!"
end if
else
alert "enter your email!"
form1.elements("email").focus
end if
else
alert "enter your address!"
form1.elements("addr").focus
end if
else
msgbox "enter your name please!"
form1.elements("name").focus
end if
end sub
-->
</script>
</head>
<body>
<form name="form1" method=post action="bug.html">
your name:<input type="text" name="name"><br>
your addr:<input type="text" name="addr"><br>
your email:<input type="text" name="email"><br>
<input type="button" name="btnsubmit" value="submit">
</form>
</body>
</html>
程序是给出来了,但看起来比较难懂,有时程序执行时间也比较重要,所以得精简程序代码。
正所谓:写程序容易,写经典程序难啊,那上面的程序还可以换种思维方式。改用javascript(注:学的是编程思想,不要太过计较脚本类型)
<html>
<head>
<title>abc</title>
<script language="javascript">
<!--
function form1_onsubmit()
{
if (document.form1.name.value=="")
{
alert("请设定您的登陆名。")
document.form1.name.focus()
return false
}
else if(document.form1.addr.value=="")
{
alert("请填写您的地址。")
document.form1.addr.focus()
return false
}
else if(document.form1.email.value=="")
{
alert("请填写您的E-Mail地址。")
document.form1.email.focus()
return false
}
}
-->
</script>
</head>
<body>
<form name="form1" onsubmit="return form1_onsubmit()">
your name:<input type="text" name="name"><br>
your addr:<input type="text" name="addr"><br>
your email:<input type="text" name="email"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
最后来看下循环结构吧:1到500可不是一个一个写出来的。
<script language=vbs>
for i= 1 to 500
document.write(i&"<br>")
next
</script>
当然循环不只可以用for,还可以用do while...loop等
反正程序这东西是代替我们少做了许多重复单一无聊的事——只要你合理利用程序。
应该有些成就吧,学语言,学编程就是学语法语义,学编程架构思想。
当然这要你有扎实的本语言的基础,基础是什么?你知道哪些函数吗?你知道怎么用程序怎么判断偶数吗(包含了运算)?你知道如何进行表单检测吗?你知道哪三种程序架构吗?
呵呵,把以上的程序吃透,最好再多看看脚本参考手册,跟我就可以开始ASP的上路了。
补:
Function过程与Sub过程类似,但是Function过程可以返回值。
Function过程也可以使用由调用过程传递的常数、变量或表达式作为参数。如果Function过程无任何参数,则Function语句必须包含括号()。
Function过程通过函数名返回一个值,这个值是在过程的语句中赋给函数名。Function返回值的数据类型总是Variant。