先放代码

          function init(){
            var theRequest = new Object();
            var url =decodeURI(decodeURI(location.search));//需要两次decodURL,否则容易出错
               if (url.indexOf("?") != -1) {
                 var str = url.substr(1);
                 strs = str.split("&");//以&为标识符进行隔断
                  for(var i = 0; i < strs.length; i ++) {
                    theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
                  }
               }
               var ss = theRequest['field'] + ":" + theRequest['search'];

URL地址:http://localhost:8080/cx2/index2.html?search=电除尘&field=_text_
通过javascript将search和field中的值读取并拼接起来,最后ss得到的结果是_text_:电除尘

标签: none

添加新评论