在JavaScript中,我想将一个变量设置为URL的GET部分中参数的值。
因此在JavaScript中:
<script> param1var = ... // ... would be replaced with the code to get asdf from URI </script>
会是什么?
这是一些。
<script> var param1var = getQueryVariable("param1"); function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); if (pair[0] == variable) { return pair[1]; } } alert('Query Variable ' + variable + ' not found'); } </script>