【ASP】ASP vbscript几个很简单的程序,获取时间、访问次数等

时间:2021-08-07 07:31:53

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
'cookie代码
dim numvisits
  response.cookies("numvisits").Expires=date+365
  numvisits=request.Cookies("NumVisits")
  
  if numvisits=""then
  	response.Cookies("NumVisits")=1
	response.Write("welcome! This is the first time you visit the page")
	else
	response.Cookies("NumVisits")=numvisits+1
	response.Write("之前你访问过"&numvisits)
	end if
%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<%
sub vbproc(num1,num2)
response.Write((num1*num2))
end sub
%>


</head>



<body>
<p>Hello World Program</p>
<%="hello world"%>
<p>字符串输出</p>
<% dim name
name="Donald Duck"
response.Write("My Name is:"&name)
%>
<p>for循环</p>
<%
Dim fname(5),i
fname(0)="Gergone0"
fname(1)="Gergone1"
fname(2)="Gergone2"
fname(3)="Gergone3"
fname(4)="Gergone4"
fname(5)="Gergone5"
for i=0 to 5
      response.Write(fname(i) & "<br></br>")
next
%>
<p>字符串循环输出</p>
<%
for i=1 to 5
	response.Write("<h"&i&">"&i&"</h"&i&">")
next
%>
<p>4.获取时间</p>
<%
dim h
h=hour(now())
response.Write("<p>现在时间:"&now()&"(Beijing Time)</p>")
if h>12 then
	response.Write("Good Morning")
	else
	response.Write("Good Day!")
	end if
%>
<p>5.程序的调用(主程序在head中)</p>
<p>您可以这样调用一个程序</p>
<p>结果:<%call vbproc(3,4)%></p>

<p>6,一个提交按钮</p>
<form action="index.asp" method="get">
Your Name:<input type="text" name="f" size="20"/>
<input type="submit" value="提交" />
</form>
<%
dim f
f=request.QueryString("f")
if f<>""then
	response.Write("你好"&f&"<br />")
	end if
%>

<form action="index.asp" method="get">
您的姓名:<input type="text" name="a" size="20" />
<input type="submit" value="提交" />
</form>
<%
dim a
a=Request.QueryString("a")
If a<>"" Then
      response.Write(a)
      response.Write("你好" & a & "<br />")
      Response.Write("今天过得怎么样?")
End If
%>
<p>7.单选按钮</p>
<%
dim cars
cars=request.Form("cars")
%>
<form action="index.asp" method="post">
<p>请选择你喜欢的汽车</p>

<input type="radio" name="cars"
<%if cars="Volvo" then Response.Write("checked")%>
value="Volvo">Volvo</input>
<br/>
<input type="radio" name="cars"
<%if cars="Saah" then response.Write("checked")%>
value="Saah">Saab</input>
<br/>
<input type="radio" name="cars"
<% if cars="BMW" then response.Write("checked")%>
value="BMW" >BMW</input>
<br /><br />
<input type="submit" value="提交" />
</form>
<%
if cars<>""then
	response.Write("<p>您喜欢的车是"&cars&"</p>")
	end if
%>

</body>
</html>