获取浏览器地址栏字符串参数
// ?name='?post=1111&action=add"
1 var urlParams = new URLSearchParams(window.location.search); 2 console.log(urlParams.has('post')); // true 3 console.log(urlParams.get('action')); // add 4 console.log(urlParams.getAll('action')); // ["add"] 5 console.log(urlParams.toString()); // post=1111&action=add 6 console.log(urlParams.append('active', 100)); // post=1111&action=add&active=100 7 console.log(urlParams.get('active')); // 100
注释:URLSearchParams存在兼容性问题
本文来自博客园,作者:红石榴21,转载请注明原文链接:https://www.cnblogs.com/liushihong21/p/11275765.html

浙公网安备 33010602011771号