栏目列表
当前位置: 首页>>化学家园>>习题下载>>同步练习>>文章内容
简单入门ASP子程序
发布时间:2009-03-14   点击:   来源:互联网   作者:未知
  在 ASP 中,你可通过 VBScript 和其他方式调用子程序。

  实例:

  调用使用 VBScript 的子程序
  <html>
  <head>
  <%
  sub vbproc(num1,num2)
  response.write(num1*num2)
  end sub
  %>
  </head>
  <body>
  <p>您可以像这样调用一个程序:</p>
  <p>结果:<%call vbproc(3,4)%></p>
  <p>或者,像这样:</p>
  <p>结果:<%vbproc 3,4%></p>
  </body>
  </html>
  如何从 ASP 调用以 VBScript 编写的子程序。
  调用使用 JavaScript 的子程序
  <%@ language="javascript" %>
  <html>
  <head>
  <%
  function jsproc(num1,num2)
  {
  Response.Write(num1*num2)
  }
  %>
  </head>
  <body>
  <p>
  结果:<%jsproc(3,4)%>
  </p>
  </body>
  </html>

  如何从 ASP 调用以 JavaScript 编写的子程序。

  调用使用 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>结果:<%call vbproc(3,4)%></p>
  <p>结果:<%call jsproc(3,4)%></p>
  </body>
  </html>

  如何在一个 ASP 文件中调用以 VBScript 和 JavaScript 编写的子程序。
  子程序

  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 子程序时,必须在子程序名后使用括号。
关闭窗口
打印文档
附件:

    主办单位:常州市新北区奔牛初级中学    苏ICP备10201501号-3
    地址:常州市新北区奔牛中天南路61号
    技术支持:新北区教师发展中心、常州万兆网络科技有限公司    访问统计