获取url参数

var url="http://localhost:8088/toChuFangDetails?code=1&codeM=m2&status=3";
var index=url.indexOf('?');
var spilitUrl=url.indexOf('&');
var typeNum;
var code;
var status;
if(spilitUrl>=1){
  var newUrl=url.substr(index+1);
  var arrList=newUrl.split("&");
  //console.log(arrList);
  var newArr = [];
  for(var i = 0; i < arrList.length; i++){
    var nnum = arrList[i].indexOf("=");
    newArr.push(arrList[i].substring(0,nnum));
    newArr.push(arrList[i].substr(nnum + 1));
  }
  typeNum=newArr[3];
  code=newArr[1];
  console.log(newArr);//["code", "1", "codeM", "m2", "status", "3"]
  if(newArr.length==6){
    status=newArr[5];
    alert(6);
  }else if(newArr.length==4){
    alert(4);
  }
}else{
  if(index!=-1){
    typeNum=url.split('?')[1].split("=")[1];
  }
}
console.log("typeNum:"+typeNum+" code:"+code+" status:"+status);

posted @ 2019-04-08 17:03  lyt598  阅读(109)  评论(0编辑  收藏  举报