






















今天遇到一个需要用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) 评论() 收藏 举报
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。