<%@ language="javascript" %> <html> <head> <% function jsproc(num1,num2) { Response.Write(num1*num2)}%></head><body><p>Result: <%jsproc(3,4)%></p></body></html>
<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中子程序的應用之ASP基礎教程
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編寫的ASP文件中調用VBScript或者JavaScript子程序時,可以使用關鍵詞"call",后面跟著子程序名稱。假如子程序需要參數,當使用關鍵詞"call"時必須使用括號包圍參數。假如省略" call",參數則不必由括號包圍。假如子程序沒有參數,那么括號則是可選項。
當從一個用JavaScript編寫的ASP文件中調用VBScript或者JavaScript子程序時,必須在子程序名后使用括號。
新聞熱點
疑難解答