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

推荐订阅源

L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Heimdal Security Blog
S
Security @ Cisco Blogs
N
News | PayPal Newsroom
J
Java Code Geeks
罗磊的独立博客
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic
V
V2EX
WordPress大学
WordPress大学
Google Online Security Blog
Google Online Security Blog
N
News and Events Feed by Topic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
AI
AI
小众软件
小众软件
The GitHub Blog
The GitHub Blog
MongoDB | Blog
MongoDB | Blog
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
美团技术团队
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
S
Schneier on Security
博客园 - 三生石上(FineUI控件)
F
Full Disclosure
B
Blog RSS Feed
Forbes - Security
Forbes - Security
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
Cisco Talos Blog
Cisco Talos Blog
U
Unit 42
Project Zero
Project Zero
H
Hacker News: Front Page
Y
Y Combinator Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
S
Secure Thoughts
The Hacker News
The Hacker News
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - ymz

C#异常的一些使用原则 【转】[翻译]Visual Studio2008的新功能:代码度量 【转】也谈c#调用C++的DLL找不到入口点 Develope express学习 【摘】异源数据转换与FDO数据访问 线程同步 线程异步 【转】ArcEngine中创建自定义工具 【转】HTML标签大全 MapGuide常见错误解决方法 集合类及泛型 一个网站系统的经验 frameset学习摘录 【转】如何使用.NET配置文件by沐枫小筑 【转】Notes on the Eclipse Plug-in Architecture 【转】理解session机制 困扰了一天的字符集转换问题 【转】Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it 【转】获取GridView单元格值的通用函数
【转贴】利用 Javascript 获取 URL 参数(适合IE、FF) - ymz
ymz · 2009-01-12 · via 博客园 - ymz

.  ... .../test.html?str=123456
如何用Javascript接收类似上面的url参数呢?这个问题网上有很多答案,看了看,主要有两种,一个是利用字符串的截取,另一种是利用正则表达式。
正则式

function QueryString(item){
     var sValue=location.search.match(new RegExp("[\?\&]"+item+"=([^\&]*)(\&?)","i"))
     return sValue?sValue[1]:sValue
}

alert(QueryString('str'));

不足就是每次只能选一个参数,当然了,你也可以修改下上面脚本,为 QueryString(item) 函数添加一个参数,例如:QueryString(item,pos) ,不过还要修改相应表达式,较为麻烦,而且没有下面这种方法灵活。

字符串(摘自:《JavaScript: The Definitive Guide, 5th Edition》)

function getArgs( ) {
     var args = new Object( );
     var query = location.search.substring(1);      // Get query string
     var pairs = query.split("&");                  // Break at ampersand
     for(var i = 0; i < pairs.length; i++) {
         var pos = pairs[i].indexOf('=');           // Look for "name=value"
         if (pos == -1) continue;                   // If not found, skip
         var argname = pairs[i].substring(0,pos); // Extract the name
         var value = pairs[i].substring(pos+1);     // Extract the value
         value = decodeURIComponent(value);         // Decode it, if needed
         args[argname] = value;                     // Store as a property
     }
     return args;                                   // Return the object
}


alert(getArgs()['str']);

alert(getArgs().str);