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

截取URL链接中字段的方法

时间:2018-06-13 18:10:01      阅读:458      评论:0      收藏:0      [点我收藏+]

标签:日期   amp   substr   code   regexp   res   one   htm   页面   

第一个页面像第二个页面传参方法

location.href = "poster.html?" + "name=" + name + "&time=" + time + "&department=" + department;

第二个页面获取参数方法  截取字段 转码即可

//截取链接中的字段
    var GetQueryString = function(key) {
      var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
      var result = window.location.search.substr(1).match(reg);
      return result ? decodeURIComponent(result[2]) : null;
    }
 var time = GetQueryString("time"); //日期

 

截取URL链接中字段的方法

标签:日期   amp   substr   code   regexp   res   one   htm   页面   

原文地址:https://www.cnblogs.com/luffyc/p/9178911.html

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