惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
美团技术团队
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
月光博客
月光博客
宝玉的分享
宝玉的分享
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
A
About on SuperTechFans
J
Java Code Geeks
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
Vercel News
Vercel News
博客园 - 聂微东

博客园 - leonardleonard

sql去重 分布式云存储系统 Riak CS 开源 转-WCF详解文档最新 .net 基础 HTTP 状态代码 大型网站架构不得不考虑的10个问题 怎么让蜘蛛喜欢你的网站 【Helper】泛型类和集合类的方法 靠垃圾站已经不能继续混下去了 初学做网站的草根站长必读 怎么样让网站有一个好听的中文名称 网站迅速产生外链的方法秘笈 想做成功网站需要注意的几个问题 一些JSON相关的函数 - leonardleonard - 博客园 Asp.NET 的Session实现原理 转自21kaiyun.com jquery技巧总结 JavaScript函数 this调用规则 只需九步让你新站成为高权重网站 影响Lucene索引速度原因以及提高索引速度技巧
21世纪开运网www.21kaiyun.com用javascript替换URL中的参数值...
leonardleonard · 2010-07-29 · via 博客园 - leonardleonard

今天遇到一个需要用javascript将url中的某些参数替换的需求:

    var a =  document.createElement('a');

        protocol: a.protocol.replace(':',''),

                seg = a.search.replace(/^\?/,'').split('&'),

                len = seg.length, i = 0, s;

                if (!seg[i]) { continue; }

        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],

        hash: a.hash.replace('#',''),

        path: a.pathname.replace(/^([^\/])/,'/$1'),

        relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],

        segments: a.pathname.replace(/^\//,'').split('/')

用法:

myURL.file;     // = 'index.html'

myURL.hash;     // = 'top'

myURL.host;     // = 'abc.com'

myURL.query;    // = '?id=255&m=hello'

myURL.params;   // = Object = { id: 255, m: hello }

myURL.path;     // = '/dir/index.html'

myURL.segments; // = Array = ['dir', 'index.html']

myURL.port;     // = '8080'

myURL.protocol; // = 'http'

取得URL的参数,以对象形式返回!

var getParam = function(path){

    var result = {},param = /([^?=&]+)=([^&]+)/ig,match;

    while((match = param.exec(path)) != null){

        result[match[1]] = match[2];

Object.keys = Object.keys || function(obj){

        if(obj.hasOwnProperty(i)){

alert(Object.keys(r))//ct,tn,sc,pn,rn,lm,rs4,rs3,word,frs

posted @ 2010-07-29 16:22  leonardleonard  阅读(878)  评论()    收藏  举报