页面之间传参问题

在Web开发的时候,难免不会遇到页面跳转,参数传递的问题。最近我就遇到了这个问题,所以写了这篇博客。自己踩过的坑,不希望再跳进去,留下记录,以后方便自己,也予人方便。

这是第一个部分页面的代码,使用的是按钮,URL的字符串拼接:

"        \n" +
            "<a  id='dianchi' class='fa fa-battery-full' style='color:#fe9e19;font-size:18px'" +
              " href=dianchixinxi"+"?shebeiCode="+shebeiCode +" ></a>" +
            "    \n" +
            "<a id='dianyuanxinxi' target='_blank' class='fa fa-plug' style='color:#b52c26;font-size:18px' " +
              "href=dianyuanxinxi"+"?shebeiCode="+shebeiCode +" ></a>" +
            "    \n" +
            "<a id='xiangxi' class='fa fa-fax' style='color:#9889c1;font-size:18px'" +
            "href=xiangxixinxi"+"?shebeiCode="+shebeiCode +" ></a>"

通过URL字符串拼接,将需要传递的参数拼接在后面,当鼠标选中跳转页面的按钮是,URL带参数:


    

接下来就是跳转后的页面了:

跳转以后的页面,需要用JS来分割URL,把之前的页面传递的参数提取出来,并提交给后台,让后台通过比对,然后再把需要数据传到页面显示。

function GetRequest() {
           var url = location.search; //获取url中"?"符后的字串
           var theRequest = new Object();
           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]]=unescape(strs[i].split("=")[1]);
              }
           }
           //console.log(theRequest);
           return theRequest;
        }

以上就是全部代码,谢谢观看!推荐一下,我的群:789826996


猜你喜欢

转载自blog.csdn.net/u011798443/article/details/80430275