码迷,mamicode.com
首页 > Web开发 > 详细

获取url的数据

时间:2014-12-14 19:50:13      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   for   on   

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com">
<meta name="copyright" content="智能社 - zhinengshe.com">
<title>智能社 - www.zhinengshe.com</title>
<script>
    // http://baidu.com?name=harry&age=18&sex=1
    /*
        {
            name: harry,
            age:18,
            sex:1    
        }
        
        ?name=harry&age=18&sex=1
        name=harry&age=18&sex=1
        name=harry
        age=18
        sex=1
    */
// var sSeach=window.location.search;
var sSeach=?name=harry&age=18&sex=1;
var url=sSeach.substring(1);

var arr=url.split(&);//分割字符串为数组
var json={};
for(var i=0; i<arr.length;i++)
{
    var aTmp=arr[i].split(=);
    var name=aTmp[0];
    var value=aTmp[1];
    json[name]=value;
    
}
alert(JSON.stringify(json));//json的内容

</script>
</head>

<body>
</body>
</html>

 

获取url的数据

标签:style   blog   http   io   ar   color   sp   for   on   

原文地址:http://www.cnblogs.com/heboliufengjie/p/4162809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!