<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>测试提取url的参数</title>
<script type="text/javascript">
function getQueryObj(url) {
const noMatchData = {};
if (!url || typeof url !== 'string') return noMatchData;
const reg = /(?:\?|&)(?:(?:([^=&]+?)=([^&#]+))|([^&#]+))/gi;
const obj = {};
url.replace(reg, function(match, $1, $2='', $3) {
if ($3) {
obj[$3] = '';
} else {
obj[$1] = encodeURIComponent($2);
}
});
return obj
}
var rs = getQueryObj("http://sample.com?aa=88&jjj=9&code=123456&key&xx=juh#678");
console.log(rs);
</script>
</head>
<body>
js函数提取字符串url的参数
最新推荐文章于 2024-06-04 19:55:06 发布