<script> function getQeuryVariable(variable) { let query = window.location.search.substring(1) console.log(query) let vars = query.split('&') for (let i = 0; i < vars.length; i++) { let pair = vars[i].split('=') console.log(pair) if (pair[0] === variable) { return pair[1] } } return false } let userName = getQeuryVariable('userName') console.log(userName) </script>
url 例子: http://localhost:3000/index?userName=dev
调用 getQeuryVariable('userName')
返回用户名 dev