js通过问号后面拿参数

     $(function () {
        var search = location.search;
       // alert(search); //获取URL中?后的句子
        var string = search.split("=")[1]; //分割取出cid
        // alert(string);
        var games = getParameter("game"); //通过getParameter获取
        if(games){
          alert(games);

        }
        //根据传递过来的参数name获取对应的值
        function getParameter(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
            var r = location.search.substr(1).match(reg);
            if (r!=null) return (r[2]); return null;
        }
    });

127.0.0.1:8080/?game=shqz

你可能感兴趣的:(javascript)