传递参数: window.location='editCourse.html?dataId='+dataId+'';

获取url中的参数(封装的方法):

   function getUrlParam(name) {

        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象

        var r = window.location.search.substr(1).match(reg);  //匹配目标参数

        if (r != null) return unescape(r[2]);

        return null; //返回参数值

    }


使用:
var dataId = getUrlParam("dataId")

或者

jobDetail(index) {
     location.replace("job_detail.html?jobId=" + index);
}
//获得传过来的login与在数据库中对应的表单
var paras = location.search;            //search获得地址中的参数,内容为'?itemId=12'
var result = paras.match(/[^\?&]*=[^&]*/g);     //match是字符串中符合的字段一个一个取出来,result中的值为['login=xx','table=admin']
paras = {};                    //让paras变成没有内容的json对象
for(i in result){
    var temp = result[i].split('=');    //split()将一个字符串分解成一个数组,两次遍历result中的值分别为['itemId','xx']
    paras[temp[0]] = temp[1];
}
var itemId = paras.itemId;     //根据参数名"itemId",获取参数值
console.log(itemId);

 

相关文章:

  • 2022-12-23
  • 2021-11-20
  • 2021-10-30
  • 2021-10-12
猜你喜欢
  • 2021-07-08
  • 2022-12-23
  • 2021-11-08
  • 2021-06-18
  • 2021-07-25
  • 2022-12-23
  • 2022-01-16
相关资源
相似解决方案