JS 获取URL中参数的值

2017-05-23  本文已影响0人  jasonlu1208
var testParam = getUrlParam("xxx")

      //paraName 等找参数的名称
  function getUrlParam(paraName) {
    var url = document.location.toString();
    var arrObj = url.split("?");

    if (arrObj.length > 1) {
      var arrPara = arrObj[1].split("&");
      var arr;

      for (var i = 0; i < arrPara.length; i++) {
        arr = arrPara[i].split("=");

        if (arr != null && arr[0] == paraName) {
          return arr[1];
        }
      }
      return "";
    }
    else {
      return "";
    }
  }
上一篇下一篇

猜你喜欢

热点阅读