ASP基礎教程之學習ASP中子程式的應用

來源:互聯網
上載者:User
程式|基礎教程

在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子程式時,必須在子程式名後使用括弧。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.