前端使用正则表达式从接口地址栏取值并将对应的值展示在页面上

139 阅读1分钟

业务场景,APP分享出链接,通过get请求接口方式,展示对应的字段。

需求图:

 

获取某单号

        var name="";//姓名
		var idNo="";//证件号
		var applicationNo=getParams("applicationNo");//号码
		window.onload = function(){
			fetch("https://xxxxx/picc-interface/queryApplicantFiveElements?applicationNo=" + applicationNo)
			.then(response => response.json())
			.then(res=>{
				$("#applicantN").html(res.name);
				$("#idN").html(res.idNo);
				$("#applicationN").html(res.applicationNo);
				})
		}

获取浏览器参数

function getParams(name) {
		  	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return "";
		}