js页面路径拼接字符串进行参数传递

时间:2023-03-09 00:34:00
js页面路径拼接字符串进行参数传递

页面路径拼接字符串进行参数传递:

参数传递页面:

<style>
input,button{
border: 1px solid red;
}
body {
font-size:24px;
}
</style>
<body>
<input id="username" type="text" name="username">用户名<br>
<input type="text" id="sex" name="sex">性别<br>
<button id="btn">提交</button>
<script src="js/jquery.min.3.2.js"></script>
<script>
$("#btn").click(function () {
url = "Read.html?username=" + escape(document.all.username.value);//Read.html接收页面
url += "&sex=" + escape(document.all.sex.value);
document.getElementById("username").value = "";
document.getElementById("sex").value = ""; location.href = url;
})
</script>
</body>

js页面路径拼接字符串进行参数传递

参数接收页面

<body>
<div class="content"></div><br>
<div class="content2"></div>
<script src="js/jquery.min.3.2.js"></script>
<script language="javascript" >
/*
3 *--------------- Read.html -----------------
4 * Request[key]
5 * 功能:实现ASP的取得URL字符串,Request("AAA")
6 * 参数:key,字符串.
7 * 实例:alert(Request["AAA"])
8 *--------------- Request.htm -----------------
9
*/
var url=location.search;
console.log(url);//?username=1&sex=2
var Request = new Object();
if(url.indexOf("?")!=-1){
  var str = url.substr(1) //去掉?号
  strs = str.split("&");
  for(var i=0;i<strs.length;i++){
    Request[strs[i ].split("=")[0]]=unescape(strs[ i].split("=")[1]);
  }
}
$(".content").html(Request["username"])
$(".content2").html(Request["sex"])
</script>
</body>

js页面路径拼接字符串进行参数传递