自定义目录标题
一.VBScript简介
VBScript 是微软公司出品的脚本语言。VBScript 是ASP (Active Server Pages)默认使用的脚本语言。
二.基本使用
1.输出
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
document.write("hello world")
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
2.变量
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Dim name // 声明变量
name = "world"
age = 18
document.write(name & Chr(10) & age)
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
3.调用函数
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Function testfunction(a, b)
c = a + b
testfunction = a + c
End Function
document.write(testfunction(1,3))
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
4.条件语句
1.Select Case
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
d=weekday(date)
Select Case d // Select Case
Case 1
document.write("Sleepy Sunday")
Case 2
document.write("Monday again!")
Case 3
document.write("Just Tuesday!")
Case 4
document.write("Wednesday!")
Case 5
document.write("Thursday...")
Case 6
document.write("Finally Friday!")
Case else
document.write("Super Saturday!!!!")
End Select
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
2.If…Then…Else
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Function YLove(you) // 程序 If ... Then ... Else
If you = "love" Then
result = "Let's get married"
Else
result = "But i love you"
End If
YLove = result
End Function // 程序结束 "<br />" 换行
document.write(YLove("love") & "<br />" & YLove("not love"))
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
3.If … Then … ElseIf
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
i=hour(time)
If i = 10 Then
document.write("Just started...!")
ElseIf i = 11 Then
document.write("Hungry!")
ElseIf i = 12 Then
document.write("Ah, lunch-time!")
ElseIf i = 16 Then
document.write("Time to go home!")
Else
document.write("Unknown")
End If
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
5.循环
1. For … Next
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
For i = 0 To 3
document.write("The number is " & i & "<br />")
Next
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
2. For Each … Next
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Dim cars(2)
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x In cars
document.write(x & "<br />")
Next
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
3. Do While … Loop
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
i = 16
Do While i>10
i = i - 2
document.write("this i is number " & i & "<br />")
Loop
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
以上所有实例皆可以在 windows 系统创建 .hta 文件双击运行