zoukankan      html  css  js  c++  java
  • url 地址处理(截取,参数等)

    function hrefObj() {
      var localhref = window.location.href;
       var localarr = localhref.split('?')[1].split('&');
       console.log(localarr)
       var tempObj = {};
       for (var i = 0; i < localarr.length; i++) {
         tempObj[localarr[i].split('=')[0]] = localarr[i].split('=')[1];
        console.log(i)
       }
      return tempObj;
    }
    
    
    
    // 截取地址参数
    function getCode() {
      var aId = window.location.href.split('?')[1].split('=')[1];
      return aId;
    }    
    截取地址字符串分隔
    // var openid = $state.params.openid;
    var paramsArr = location.href.match(/?S+/)[0].replace('?', '').split('&');
    vm.params = {};
    for (var i = 0; i < paramsArr.length; i++) {
        var tmp = paramsArr[i].split('=');
        vm.params[tmp[0]] = tmp[1];
    }
    var urlStr = window.location.href.split('?')[1].split('&')[0].split('=')[1]
    
    function getUrlParam(key) {
        var url = window.location.search.substring(1);
        var par = url.split('&');
        for (var i = 0; i < par.length; i++) {
            var code = par[i].split('=');
            if (key == code[0]) return code[1];
        }
        return "";
    }
    调用获取code
    var code = getUrlParam('code')
     
    export function getUrlParams(key) {
      let url = window.location.href;
      const arr = url.split("?");
      const newArr = arr[1] ? arr[1].split("&") : [];
      for (var i = 0; i < newArr.length; i++) {
        let temp = newArr[i].split("=");
        if (temp[0] === key) {
          let search = temp[1];
          if (search.indexOf("#") > 0) {
            search = search.substring(0, search.indexOf("#"));
          }
          return search;
        }
      }
    }
    this.parkId = getUrlParams('parkId')
  • 相关阅读:
    Windows Phone 一步一步从入门到精通
    备忘录模式(Memento)
    开放封闭原则(OCP)
    建造者模式(Bulider)
    原型模式(Prototype)
    Windows Workflow Foundation(WF) 一步一步从入门到精通
    模板方法模式
    代理模式(Proxy)
    装饰模式(Decorator)
    迪米特法则(LoD)最少知识原则
  • 原文地址:https://www.cnblogs.com/Byme/p/7605247.html
Copyright © 2011-2022 走看看