BOM

1、(1) location对象:
console.log(window.location.href); //返回当前加载页面的完整URL
// console.log(window.location.toString()); //返回当前加载页面的完整URL
console.log(window.location.search); //返回URL的查询字符串。这个字符串以?开头
(2) 查询字符串参数
//创建一个函数,用以解析查询字符串,然后返回所有参数的一个对象 书籍:高级程序设计207
function getQueryStringArgs(){
//取得查询字符串并去掉开头的问号
var qs = (window.location.search.length > 0 ? location.search.substring(1) : " "),

        //保存数据的对象
        args = {};
        
        //取得每一项
        items = qs.length ? qs.split("&") : [],
        item = null,
        name = null,
        value = null,
        i = 0,len = items.length;
        
        //逐个将每一项添加到args对象中
        for(var 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;
    }

    var data=getQueryStringArgs();
    console.log(data.wd);
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容