參數傳遞的四種形式----- URL,超連接,js,form表單

4種get傳參方式javascript

<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
    <title></title>  
    <script type="text/javascript">  
        function Go() {  
            window.location.href="localhost:21811/Handler1.ashx?id=1&name='abc'"  
        }  
    </script>  
</head>  
<body>  
  
   <!--//參數傳遞的幾種形式-->  
    <!--第一種:直接在URL後面加參數:-->  
    localhost:21811/Handler1.ashx?id=1&name="abc"  
  
  
    <!--第二種:用超連接的方法傳遞參數:當點擊超連接的時候,首先會跳轉到localhost:21811/Handler1.ashx頁面,而後還會傳遞id 和name 兩個參數過去-->  
    <a href="localhost:21811/Handler1.ashx?id=1&name='abc'">超連接傳遞參數</a></body>  
  
    <!--第三種:經過js方法傳遞:用戶點擊這個button按鈕,觸發onClick事件,執行Go()方法,跳轉到localhost:21811/Handler1.ashx頁面,同時傳遞了id,和name兩個參數過去-->  
    <input type="button" onclick="Go()" value="經過js方法傳遞參數" />  
  
      
    <!--第四種:經過form表單傳遞-->  
    <form action="Handler1.ashx" method="get"><!--注意action裏面的鏈接不能帶參數的-->>  
        <input type="text" name="id" value="3" />  
        <input type="text" name="name" value="abc" />  
        <input type="submit" value="經過傳遞參數" />  
    </form>  
</body>  
</html>  
相關文章
相關標籤/搜索