zoukankan      html  css  js  c++  java
  • js获取url的参数和值的N种有效方法

    js获取url的参数和值的N种有效方法

    function getParameterByName(name)  
    {  
      name = name.replace(/[[]/, "\[").replace(/[]]/, "\]");  
      var regexS = "[\?&]" + name + "=([^&#]*)";  
      var regex = new RegExp(regexS);  
      var results = regex.exec(window.location.search);  
      if(results == null)  
        return "";  
      else  
        return decodeURIComponent(results[1].replace(/+/g, " "));  
    }  
    function getParameterByName(name) {  
        var match = RegExp('[?&]' + name + '=([^&]*)')  
                        .exec(window.location.search);  
        return match && decodeURIComponent(match[1].replace(/+/g, ' '));  
    } 
    var qs = (function(a) {  
        if (a == "") return {};  
        var b = {};  
        for (var i = 0; i < a.length; ++i)  
        {  
            var p=a[i].split('=');  
            if (p.length != 2) continue;  
            b[p[0]] = decodeURIComponent(p[1].replace(/+/g, " "));  
        }  
        return b;  
    })(window.location.search.substr(1).split('&'));  
    $.urlParam = function(name){  
        var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);  
        if (!results)  
        {   
            return 0;   
        }  
        return results[1] || 0;  
    }  
  • 相关阅读:
    NET CORE 数据库迁移
    VUE3.0 解析svg文件
    关于ElementUI的样式不生效
    git命令
    vue 2.x的跨域问题
    Putty 重新启动 linux sqlserver服务
    aspnetcore之session
    Syncfusion 在 core 的架构
    TortoiseSVN创建/合并分支
    正则表达式知识点整理
  • 原文地址:https://www.cnblogs.com/hewasdrunk/p/7465900.html
Copyright © 2011-2022 走看看