zoukankan      html  css  js  c++  java
  • js获取url查询字符串参数

    最近看js高级程序设计

    对其中查询字符串参数的获得重新写了,当传递一个完整的URL的时候对查询字符串的提取

    function getQueryArgs(){
        var qs = (location.search.length > 0 ? location.search.substr(1) : ''),
            //保存每一项
            args = {},
            //得到每一项
            items = qs.length ? qs.split('&') : [],
            item = null,
            name = null,
            value = null,
            i = 0,
            len = items.length;
    
            for(i = 0;i<len ;i++){
                item = items[i].split('='),
                name = decodeURIComponent(item[0])
                value = decodeURIComponent(item[1])
                if(name.length){
                    args[name] = value;
                }
            }
            return args;
    }
    getQueryArgs()
    function getQueryArgs(url){
        var qs = (url.length > 0 ? url.substring(url.indexOf('?')).substr(1) : ''),
            //保存每一项
            args = {},
            //得到每一项
            items = qs.length ? qs.split('&') : [],
            item = null,
            name = null,
            value = null,
            i = 0,
            len = items.length;
    
            for(i = 0;i<len ;i++){
                item = items[i].split('='),
                name = decodeURIComponent(item[0])
                value = decodeURIComponent(item[1])
                if(name.length){
                    args[name] = value;
                }
            }
            return args;
    }
    

      

  • 相关阅读:
    其他魔术方法
    类型约束和类的魔术常量
    PHP对象遍历、内置标准类与数据转对象
    类的自动加载与对象的克隆
    PHP重载与接口
    面向对象
    PHP基础
    地下城与勇士的项目整理
    mysql建表
    jQuery
  • 原文地址:https://www.cnblogs.com/qqfontofweb/p/10637298.html
Copyright © 2011-2022 走看看