怎么用 JavaScript 接受参数 window.location.search.split("id=")[1]就是你的10这里只是举例说的具体URL是window.location.href这个字串,自己分离出来吧... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 a.htm////////////////////<SCRIPT>function getUrlParameter(asName){ var lsURL=window.location.href; loU = lsURL.split("?"); if (loU.length>1){ var loallPm = loU[1].split("&"); for (var i=0; i<loallPm.length; i++){ var loPm = loallPm[i].split("="); if (loPm[0]==asName){ if (loPm.length>1){ return loPm[1]; }else{ return ""; } } } } return null;}alert(getUrlParameter("id"));</SCRIPT> 给你两段代码看看应该就懂了// from.html<html><head><meta http-equiv="Content-Type" content="text/html; charset=shift_jis"><title>Untitled Document</title></head><script>function moveValue(){ var str = document.all.from.value; window.location.href = "to.html?from=" + str;}</script><body><form><center><input name="from" type="text"><input name="btn" type="button" value="button" onClick="moveValue();"></center></form></body></html>//to.html<html><head><meta http-equiv="Content-Type" content="text/html; charset=shift_jis"><title>Untitled Document</title></head><script>var sHref = window.location.href;var sArgName = "to";function init(sHref,sArgName){ var args = sHref.split("?"); var retval = ""; if(args[0] == sHref){ return; } var str = args[1]; var arg = str.split("="); if(arg.length <= 1){ return; } retval = arg[1]; document.all.to.value = retval; return retval;}</script><body onLoad="init(sHref,sArgName);"><form><center><input name="to" type="text"></center></form></body></html>从from按按钮到to,to接受from传过来的值 window.locationhash 设置或获取 href 属性中在井号“#”后面的分段。 host 设置或获取 location 或 URL 的 hostname 和 port 号码。 hostname 设置或获取 location 或 URL 的主机名称部分。 href 设置或获取整个 URL 为字符串。 pathname 设置或获取对象指定的文件名或路径。 port 设置或获取与 URL 关联的端口号码。 protocol 设置或获取 URL 的协议部分。 search 设置或获取 href 属性中跟在问号后面的部分。 测试例<script>url = location.search.substr(1);if(url.length > 0) { ar = url.split(/[&=]/); for(i=0;i<ar.length;i+=2) { document.write("参数:"+ar[i]+":"+ar[i+1]+"<br>"); eval(ar[i]+"='"+ ar[i+1]+"'"); } document.write("变量room:"+room+"<br>"); document.write("变量a:"+a+"<br>");}</script><a href='?a=你好&room=awe'>test</a> <script>var JSvar=<%=request.getParameter('id')%></script> 在 xxx.html?id=10 页面里:<script language="javascript">String.prototype.getQueryString = function(name){ var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)"), r; if (r=this.match(reg)) return unescape(r[2]); return null;};alert(window.location.href.getQueryString("id"));</script> 楼上的解决方法应该都可以,如果参数比较多就应该用indexOf和substring两个函数来处理 <script>url = location.search.substr(1);if(url.length > 0) { ar = url.split(/[&=]/); for(i=0;i<ar.length;i+=2) { document.write("参数:"+ar[i]+":"+ar[i+1]+"<br>"); }}</script><a href='?a=你好&room=awe'>test</a>参数参考window.locationhash 设置或获取 href 属性中在井号“#”后面的分段。 host 设置或获取 location 或 URL 的 hostname 和 port 号码。 hostname 设置或获取 location 或 URL 的主机名称部分。 href 设置或获取整个 URL 为字符串。 pathname 设置或获取对象指定的文件名或路径。 port 设置或获取与 URL 关联的端口号码。 protocol 设置或获取 URL 的协议部分。 search 设置或获取 href 属性中跟在问号后面的部分。 var strParameter = window.location.search.substring(1);var id = strParameter.split('&')[0].split('=')[1]; function get_id(){ return location.href.split('id=').pop();} 如果要网页中插入播放器 求助,请问这样的JS效果怎么实现? 获取属性??? JAVASCRIT怎么读取文件 JavaScript 层随着鼠标望下移动,现在想不动,解决了全分相送! ■■高分请教:如何得到listbox的显示值呢?如下例子:■■ 请问如何从select中删除option初学者 急 我想打出分号。请问如何实现。如:alert (""");应怎样编了。 为什么不响应onchange事件 怎样在网页上面怎样控制real的声音啊? 就是用其他图片来代替real组件上的声音调节 javascritp问题,在线急等!!! 求AJAX JS包
////////////////////
<SCRIPT>
function getUrlParameter(asName){
var lsURL=window.location.href;
loU = lsURL.split("?");
if (loU.length>1){ var loallPm = loU[1].split("&"); for (var i=0; i<loallPm.length; i++){
var loPm = loallPm[i].split("=");
if (loPm[0]==asName){
if (loPm.length>1){
return loPm[1];
}else{
return "";
}
}
}
}
return null;
}alert(getUrlParameter("id"));
</SCRIPT>
// from.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>Untitled Document</title>
</head>
<script>
function moveValue()
{
var str = document.all.from.value;
window.location.href = "to.html?from=" + str;
}
</script>
<body>
<form>
<center>
<input name="from" type="text">
<input name="btn" type="button" value="button" onClick="moveValue();">
</center>
</form>
</body>
</html>
//to.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>Untitled Document</title>
</head>
<script>
var sHref = window.location.href;
var sArgName = "to";
function init(sHref,sArgName)
{
var args = sHref.split("?");
var retval = "";
if(args[0] == sHref){
return;
}
var str = args[1];
var arg = str.split("=");
if(arg.length <= 1){
return;
}
retval = arg[1];
document.all.to.value = retval;
return retval;
}
</script>
<body onLoad="init(sHref,sArgName);">
<form>
<center>
<input name="to" type="text">
</center>
</form>
</body>
</html>从from按按钮到to,to接受from传过来的值
hash 设置或获取 href 属性中在井号“#”后面的分段。
host 设置或获取 location 或 URL 的 hostname 和 port 号码。
hostname 设置或获取 location 或 URL 的主机名称部分。
href 设置或获取整个 URL 为字符串。
pathname 设置或获取对象指定的文件名或路径。
port 设置或获取与 URL 关联的端口号码。
protocol 设置或获取 URL 的协议部分。
search 设置或获取 href 属性中跟在问号后面的部分。
<script>
url = location.search.substr(1);
if(url.length > 0) {
ar = url.split(/[&=]/);
for(i=0;i<ar.length;i+=2) {
document.write("参数:"+ar[i]+":"+ar[i+1]+"<br>");
eval(ar[i]+"='"+ ar[i+1]+"'");
}
document.write("变量room:"+room+"<br>");
document.write("变量a:"+a+"<br>");
}
</script><a href='?a=你好&room=awe'>test</a>
var JSvar=<%=request.getParameter('id')%>
</script>
<script language="javascript">
String.prototype.getQueryString = function(name)
{
var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)"), r;
if (r=this.match(reg)) return unescape(r[2]); return null;
};alert(window.location.href.getQueryString("id"));
</script>
<script>
url = location.search.substr(1);
if(url.length > 0) {
ar = url.split(/[&=]/);
for(i=0;i<ar.length;i+=2) {
document.write("参数:"+ar[i]+":"+ar[i+1]+"<br>");
}
}
</script><a href='?a=你好&room=awe'>test</a>参数参考
window.location
hash 设置或获取 href 属性中在井号“#”后面的分段。
host 设置或获取 location 或 URL 的 hostname 和 port 号码。
hostname 设置或获取 location 或 URL 的主机名称部分。
href 设置或获取整个 URL 为字符串。
pathname 设置或获取对象指定的文件名或路径。
port 设置或获取与 URL 关联的端口号码。
protocol 设置或获取 URL 的协议部分。
search 设置或获取 href 属性中跟在问号后面的部分。
var id = strParameter.split('&')[0].split('=')[1];
return location.href.split('id=').pop();
}