当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP基础教程之学习ASP中子程序的应用

ASP
统计在线人数 dxy
ASP 写的自动生成SELECT 表单的函数
自己做采集程序
巧用缓存提高asp程序的性能
多字段模糊搜索的函数
打包上传asp网站
FreeTextBox 中文版下载[含源代码] of asp.net
asp 防止SQL注入代码
asp实现无限级分类的方法js版
多附件上传组件演示
替换数据库内容
E-mail表单递交
也谈采集入库的技术
先锋海盗类
XML相关技术资料
让ASP搭配MYSQL
ASP远程保存图片
整理了下手动注入脚本命令[带注释]
也谈跨站脚本攻击与防御
突破空格的限制

ASP基础教程之学习ASP中子程序的应用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 91 ::
收藏到网摘: n/a

在ASP中,你可通过VBScript和其他方式调用自程序。

实例:

调用使用VBScript的子程序
如何从ASP调用以VBScript编写的子程序。
 <html>

<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>

<body>
<p>
You can call a procedure like this:
</p>
<p>
Result: <%call vbproc(3,4)%>
</p>
<p>
Or, like this:
</p>
<p>
Result: <%vbproc 3,4%>
</p>
</body>

</html>
调用使用JavaScript的子程序
如何从ASP调用以JavaScript编写的子程序。
<%@ language="javascript" %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>
<p>
Result: <%jsproc(3,4)%>
</p>
</body>
</html>
调用使用VBScript和JavaScript的子程序
如何在一个ASP文件中调用以VBScript和JavaScript编写的子程序。
<html>
<head>
<%
sub vbproc(num1,num2)
Response.Write(num1*num2)
end sub
%>
<script language="javascript" runat="server">
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
</script>
</head>
<body>
<p>Result: <%call vbproc(3,4)%></p>
<p>Result: <%call jsproc(3,4)%></p>
</body>
</html>

子程序

ASP源代码可包含子程序和函数:

<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>Result: <%call vbproc(3,4)%></p>
</body>
</html>

将<%@ language="language" %>这一行写到<html>标签的上面,就可以使用另外一种脚本语言来编写子程序或者函数:

<%@ language="javascript" %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>
<p>Result: <%jsproc(3,4)%></p>
</body>
</html>

VBScript与JavaScript之间的差异

当从一个用VBScript编写的ASP文件中调用VBScript或者JavaScript子程序时,可以使用关键词"call",后面跟着子程序名称。假如子程序需要参数,当使用关键词"call"时必须使用括号包围参数。假如省略"call",参数则不必由括号包围。假如子程序没有参数,那么括号则是可选项。

当从一个用JavaScript编写的ASP文件中调用VBScript或者JavaScript子程序时,必须在子程序名后使用括号。