ASP學習----基本用法和表單

來源:互聯網
上載者:User

標籤:asp   基本用法   表單   

ASP寫法:

     寫法1:<%="Hello World!"%>

     寫法2:<%

              Response.Write("Hello World!")

            %>


ASP聲明變數:使用dim

     如下:

         <html>

         <body>

            <%

              dim name

              name = "xiaohong"

              Response.write("your name is:"+name & "<br/>")

            %>

         </body>

         </html>


ASP聲明數組:dim arrayname(arraylength)

         <html>

         <body>

            <%

              Dim names(3),i

              names(0) = "zero"

              names(1) = "one"

              names(2) = "two"

              names(3) = "three"

              For i=0 to 3

                response.write("names is:"+names(i) & "<br/>")

              next

            %>


ASP使用迴圈:

         <html>

         <body>

            <%

              dim j

              for j=1 to 6

              response.write("<h" & j & ">Header " & j & "</h" & j & ">")

             next

            %>


ASP使用javascript指令碼:

首先要寫上頭部:<%@ language="javascript" %>

使用了javascript,就不能用ASP的相關文法,應該用javascript的相關文法

並且javascript是要區分大小寫

<%@ language="javascript" %><html><body><%var d = new Date()var h = d.getHours()if(h<12){Response.Write("Good morning")}else{Response.Write("Good Afternoon")}%></body></html>

註:使用了<%@ language="javascript" %>,就只能使用javascript的文法規則


調用javascript編寫的函數

在head部分書寫javascript函數:<% 函數 %>

在body部分書寫調用語句

如下:

<%@ language="javascript" %><html><head><%  function test(){  var d = new Date()  var h = d.getHours()  if(h<12){  Response.Write("Good morning")  }  else{  Response.Write("Good Afternoon")  }  }%></head><body>test is:<%test()%></body></html>


寫法二:要在script標籤中說明language為javascript 

        runat="server"

<html><head><script language="javascript" runat="server">function test(){Response.Write("hello")}</script></head><body>test is:<%call test()%></body></html>

註:這樣書寫javascript代碼,可以再body中使用ASP的文法


ASP處理表單:

註:html檔案要從IIS處開啟,即將index.html檔案放到預設檔案的最頂端。

      action的值是:ASP檔案

    method的值有get和post

        如果使用get,要用 Request.QueryString(formname) 來擷取值

        如果使用post,要用 Request.Form(formname)來擷取值

    例如:

    html檔案:

<html><body><form method="get" action="index.asp">   name:    <input type="text" name="name" />   <input type="submit" value="Submit" /></form></body></html>

     ASP檔案:

<html><body>Welcome<%response.write(request.querystring("name"))%></body></html>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.