当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 详解参数传递四种形式

详解参数传递四种形式

2019年08月01日  | 移动技术网IT编程  | 我要评论

这篇文章是在日常的工作中总结出来的,下面把四种参数传递的形式展示给大家。

什么时候用get,  查,删,

什么时候用post,增,改  (特列:登陆用post,因为不能让用户名和密码显示在url上)

4种get传参方式

<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> 

通过以上代码的介绍,相信大家都会喜欢的。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网