第一种:
var a = getArgs()['参数名'];
function getArgs() {var args = {};
var query = location.search.substring(1);
// Get query string
var pairs = query.split("&");
// Break at ampersand
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('=');
// Look for "name=value"
if (pos == -1) continue;
// If not found, skip
var argname = pairs[i].substring(0,pos);// Extract the name
var value = pairs[i].substring(pos+1);// Extract the value
value = decodeURIComponent(value);// Decode it, if needed
args[argname] = value;
// Store as a property
}
return args;// Return the object
}
第二种:
1.html
<
body
>
<
form
id
=
"form1"
action
=
"2.html"
method
=
"get"
>
<
input
type
=
"button"
value
=
"click me"
id
=
"btn"
>
<
input
type
=
"text"
id
=
"t1"
name ="t1"
value
=
"zhen"
>
<
input
type
=
"radio"
id
=
"r1"
name
=
"r1"
value
=
"radio"
>
</
form
>
<
script
>
document.getElementById('btn').onclick = function(){
var text = document.getElementById('t1').value;
var radio = document.getElementById('r1').value;
document.getElementById('form1').action += '?value='+text+'&'+radio;
document.getElementById('form1').submit();
};
</
script
>
</
body
>
<
body
>
<
p
>text文本框值:<
span
></
span
></
p
>
<
p
>radio单选框值:<
span
></
span
></
p
>
<
script
>
var value = window.location.href;
var arr = value.substring(value.lastIndexOf('?') + 1,value.length).split('&');
for(var i = 0; i < arr.length; i++){
document.getElementsByTagName('span')[i].innerHTML = arr[i].split('=')[1];
}
</
script
>
</
body
>