ASP 语法学习笔记
1. 基本语法
ASP(Active Server Pages)使用 VBScript 作为默认的脚本语言,允许在 HTML 中插入脚本代码。以下为 ASP 的基本语法:
1.1 变量声明
Copy Code<%
Dim variableName
variableName = "value"
%>
1.2 条件语句
Copy Code<%
If condition Then
' do something
ElseIf otherCondition Then
' do something else
Else
' do something different
End If
%>
1.3 循环语句
For 循环
Copy Code<%
For i = 0 To 10 Step 2
' do something
Next
%>
While 循环
Copy Code<%
Do While condition
' do something
Loop
%>
1.4 函数定义
Copy Code<%
Function functionName(param1, param2)
' function body
functionName = result
End Function
%>
2. 实例
以下为一个简单的 ASP 页面,展示了变量声明、条件语句、循环语句和函数定义的应用。
Copy Code<html>
<head>
<title>ASP Syntax Example</title>
</head>
<body>
<%
Dim num
num = 5
If num > 0 Then
For i = 1 To num
Response.Write "The square of " & i & " is " & square(i) & "<br>"
Next
Else
Response.Write "Invalid input"
End If
Function square(x)
square = x * x
End Function
%>
</body>
</html>
以上 ASP 页面将输出如下内容:
Copy CodeThe square of 1 is 1
The square of 2 is 4
The square of 3 is 9
The square of 4 is 16
The square of 5 is 25