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

推荐订阅源

D
DataBreaches.Net
V
Visual Studio Blog
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
K
Kaspersky official blog
博客园 - 叶小钗
月光博客
月光博客
S
Schneier on Security
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
量子位
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
P
Privacy & Cybersecurity Law Blog
Cyberwarzone
Cyberwarzone
S
Securelist
Hugging Face - Blog
Hugging Face - Blog
B
Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Vulnerabilities – Threatpost
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
V
V2EX
MongoDB | Blog
MongoDB | Blog
博客园_首页
Recorded Future
Recorded Future
酷 壳 – CoolShell
酷 壳 – CoolShell
F
Fortinet All Blogs
GbyAI
GbyAI
Microsoft Security Blog
Microsoft Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Troy Hunt's Blog
罗磊的独立博客
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Proofpoint News Feed
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
O
OpenAI News
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
N
News | PayPal Newsroom
G
GRAHAM CLULEY
H
Hacker News: Front Page
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - 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)  评论()    收藏  举报