javascript比如 index.asp?id=xxx&name=xxx
怎么用javascript怎么能取到id的name的值呢?
方法一:
<script>
function getvalue(name)
{
var str=window.location.search;
if (str.indexOf(name)!=-1)
{
var pos_start=str.indexOf(name)+name.length+1;
var pos_end=str.indexOf("&",pos_start);
if (pos_end==-1)
{
return str.substring(pos_start);
}
else
{
return str.substring(pos_start,pos_end)
}
}
else
{
return "没有这个name值";
}
}
var strName=prompt("请输入您所要值的名字");
alert(getvalue(strName));
</script>
方法二:
在eWebEditor在线编辑器里是这样处理的,给你参考一下:
var URLParams = new Array();
var aParams = document.location.search.substr(1).split('&');
for (i=0; i < aParams.length i++){
var aParam = aParams.split('=');
URLParams[aParam[0]] = aParam[1];
}
//取得传过来的name参数
name=URLParams["name"];
方法三:
<script type="text/javascript">
Request = {
QueryString : function(item){
var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
return svalue ? svalue[1] : svalue;
}
}
alert(Request.QueryString("id"));
</script>
javascript中获取地址栏参数比如 index.asp?id=xxx&name=xxx
80酷酷网 80kuku.com