jQuery带参跳转新页面,新页面获取url多个参数的办法

需求:
a页面有多个参数
跳转到b页面
在b页面获取a页面带过来的参数
a.html

<!DOCTYPE HTML>
<html>
    <head>
        <title></title>
      
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
        <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
        <style>
          
    </style>
    </head>
    <body>
       <button  type="button" class="a">跳转到b界面</button>
    </body>
 <script>
	 //底部分类复选框取消和选中触发事件
	         $(".a").click(function() {
	             window.location.href = "b.html?username=super&workNumber=M202105241431&type=2&beginTime=2021-05-24 14:31:00&endTime=2021-05-24 14:31:00";
	         });

 </script>
</html>
 

b.html

<!DOCTYPE HTML>
<html>
	<head>
		<title></title>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
		<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
		<script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
		<style>

		</style>
	</head>
	<body>

	</body>

	<script>
		//获取对方传过来的参数
		function jqueryUrl(url) {
			debugger
			//将地址从"?"位置分割成两部分
			var arr = url.split('?');
			//取地址右边参数部分从"&"位置继续分割,成为单独参数列表
			var params = arr[1].split('&'); //得到[a=1,b=2,c=3]
			//定义一个空对象
			var obj = {};
			for (var i = 0; i < params.length; i++) {
				var param = params[i].split('='); //得到[a,1]、[b,2]、[c,3]
				obj[param[0]] = param[1]; //为对象赋值
			}
			return obj;
		}
		// url参数列表		

		var urlParams = jqueryUrl(location.href)
		console.log(urlParams)
	</script>

</html>


在这里插入图片描述

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值